Monday, December 17, 2007

Introducing Rails 2 - Part 1

W and I have decided to upgrade to rails 2.
All you need to do is to type in this command in your command prompt

gem install rails -y --source http://gems.rubyonrails.org

and ruby gem will handle the rest.
After the upgrade is completed, type

rails -- version
to check if it's 2.0.1
and that's it, you are done :)

So before we look at all the new features in rails 2, let's first find out
what has been removed.

1. @params should be replaced with params
eg: params[:data] instead of @params[:data]

the same goes for @flash, @session, @env, and @request

2. find_all & find_first should be replaced with find(:all) & find(:first)
eg: User.find(:all) instead of User.find_all
User.find(:first) instead of User.find_first
note: User.find_by_xxx is still valid

3. acts_as is gone
they are plugins now

4. render_partial should be replaced with render :partial
eg: render :partial => "user" instead of render_partial "user"

5. start_form_tag and end_form_tag should be replaced with form_for or form_tag

you can check out the api description here
http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000920

6. Pagination is gone
mainly cause it sucks (slow)

on the bright side, there are faster and cleaner pagination plugins available
the one I'm currently using is called will_paginate and it can be found at
http://rock.errtheblog.com/will_paginate


7. components are gone

8. Database adapters are gone
you can download the one you need at
http://svn.rubyonrails.org/rails/adapters/

if you are planning to upgrade, go through your codes
to make sure it's rails 2 compatible.

if you are not sure, you might want to upgrade to rails 1.2.6 first,
where they marked everything that will be removed as a deprecated function.


J

No comments: