Wednesday, February 17, 2010

First few days with Ruby on Rails. So far so good.

by Roman Leinwather

Last weekend was the official start of my new web application. This time for a change I have decided to use Ruby on Rails framework even I have not touch Ruby code before. I had a chance to work with Rails views on one of our projects at thrudigital but nothing more. I have read “the book” and watched numerous screencasts and presentations, listened to various podcast.

I opened my favorite editor (Coda but considering TextMate) and start thinking “How will I start?”.

I have some idea how the Model/View/Controller works. I know I need to create some tests for my MVC. I know I need to create migrations instead of using sql to manipulate the database and I also know that gems will do more the half of the work for me.

I am pretty confident I could somehow build the app but that is not what I want. I want to build it properly from the start. Rails work-flow kind of force you to build the app. the right way but there is a lot to learn if you want to build it really good way. I guess it is quite a lot to ask from someone who never touched the ruby code before but I am always hard on myself and want to things the best possible way.

The point where I straggle is the documentation. Every possible source of information I found on the web expects more then beginner level of knowledge. Perhaps it just feels to me that way because my knowledge is not yet on that level. The other problem is the speed that this frameworks grows and develops. You can find tutorials where they show you how to do things certain way but if it is more then year old that the advice might not be up to date. I guess it can’t be really wrong but there might be better ways of doing things.

I know I have to learn it the hard way which means try and fail. I put myself into the “rails mode” so I could make progress as fast as possible. I read book on the way to/from work, listen to podcast at work while I design when I come hope I watch screencasts and try to code.

I can see the benefits of the language and I love it! I just wish there was more sources of information for people who are just starting with Rails.

Despite of my complains, I was able to produce all of this in the first day. I setup basic layout, user authentication with all required views, pre-launch page where people can enter their email addresses which goes to database and confirmation email is sent to them. I can switch between pre-launch mode which affects the home page and all the routing. Most of this was done by using different gems. I only used few lines of code here. So that was the first day. They I have decided to create some tests. I spent 3 days studying, trying different gems and scenarios but still did not get it properly. I understand I need to test my models/views/controllers and also understand that there are different way doings things. There is the standard rails testing platform than there is rspec, cucumber. There are “features” which are basically dummy data which could be used for testing and then there are “factories” which works similar way but without the need of saving data to database. There are different types of testing = functional, unit and integration testing and this is the part I did not get yet. How should these 3 types be tested, where the test should be stored, what exactly should be tested and so on. As you can see there is lot to it and it requires couple of plugins. I also sometimes struggle with configuration of plugins.

So as you can see I am on the right track but it is not an easy journey. I will keep on going and let you guys know how it goes.

I am hoping my hosting company can run Rails without difficulties so I should be able to deploy fist part of my app with prelaunch page pretty soon.