Rails 1.2.1 => Rails 3.2.3
Actually, we started a product on 2007 with rails 1.2.1, at that time we were busy in the core development and we sincerely forgot to look about the rails updates!! in-between 3-4 years rails jumped to 3.x.x then only we realized that we are doing some funny things so started to review about 3.x.x
Almost we are out-dated, but still it is not too far .. We realized that this is right time to convert our existing 1.2.1 apps to 3.2.3 so first we have started to find the practical difficulties and possibilities and learned the followings. The following is the major things for us, you guys may meet some more, but any way it will be helpful for someone.
Lets checkout one by one.
1. RVM will helps us to manage different ruby and gems version in a same system
2. All required gems should be maintained through Gemfile, it will be useful when the time of deployment
3. You have to understand, learn and change the file route.rb
4. .rhtml is no longer in use, try to use either .html or .html.erb [I have created a script for this, let me know if any one wants] Note: .html.erb is the recommended extension
5. Need to use <%= yield %> instead of <%= @content_for_layout %> in layout
6. Here after all js, css and images are referred from ‘assets’ at /app directory instead of /public. and we can’t use /images/omie.gif here , need to use /assets/omie.gif in all of the places where we are referring images like <img> , css etc.,
7. Have to change pagination usage
@rss_pages, @rss_articles = paginate(:rss_articles, :order => "published_date DESC", :conditions => ["publication_string = ? ", "NEJM" ])
to
@rss_articles = RssArticle.paginate(:page => params[:page], :order => "published_date DESC", :conditions => ["publication_string = ? ", "NEJM" ])
Note: paginate will return only one object instead of two like what we have in our old (1.2.1) method, you can use the same object to get about page information, like @rss_articles.current_page, @rss_articules.next_page
In your old method you might uses, @rss_pages.current.next, here it is simple @rss_articles.next_page
8. Have to change paginate_by_sql
In your older method you might hacked the code in your application controller, but here the gem ‘will_paginate’ will do all of the required things for us. But of-course the usage of paginate_by_sql is bit different, look at our old method
@sql = “select * from lab_tests”
@unreviewed_pages,@labs_unreviewed = paginate_by_sql(LabTest, @sql,25)
but now we need to use as:
@labs_unreviewed = LabTest.paginate_by_sql(@sql,{:page => page, :per_page => 25})
9. use the function 'raw' to avoid HTML encoding
<% a= “<div> Test </div>” %>
<%= a %>
The output will be a html encoded like <div< Test </div>
<%= raw a %>
The output like what you expected <div> Test </div>
10. All session values (> 4kb) must maintain only through active_record_store [We can setup it through config/initializers/session_store.rb] before it is done directly in environment.rb and this one is optional in lower version.
Note: Rails 3 uses a newer version of session schema, need to remove our old one and have to migrate the newer one.
11. We can’t use render(:layout=>false) in viewer, of-course it is meaningless but some of us used in some of our old view pages (like /comp/_datepicker.rhtml) by our old developers. :p
12. request.url is enough instead of request.request_uri
13. request.env in enough instead of @request.evn to get environment keys
14. We need special plugins to use ‘act_as’ modifiers such as acts_as_list, acts_as_tree.
it is under in review, as per my current knowledge , we have to use ‘ancestry’.
ref: https://github.com/stefankroes/ancestry
rails plugin install acts_as_tree => but it raises error. need to review about it
15. DateTime is no longer work, use Time always
16. There is no remote tag , use remote specifier as argument with the helper
Say for eg:
We used link_to_remote, form_remote_tag remember ?? this is going to be just
link_to, form_tag
so the code
link_to_remote("Next",{:update => "unreviewed_block"}) become
link_to("Next",{:update => "unreviewed_block", :remote => true})
and the form_remote_tag code
<%
form_remote_tag(
<% end_form_tag %>
<%
form_tag(
<% end%>
Still there exists more.. will try to update if possible.
Actually, we started a product on 2007 with rails 1.2.1, at that time we were busy in the core development and we sincerely forgot to look about the rails updates!! in-between 3-4 years rails jumped to 3.x.x then only we realized that we are doing some funny things so started to review about 3.x.x
Almost we are out-dated, but still it is not too far .. We realized that this is right time to convert our existing 1.2.1 apps to 3.2.3 so first we have started to find the practical difficulties and possibilities and learned the followings. The following is the major things for us, you guys may meet some more, but any way it will be helpful for someone.
Lets checkout one by one.
1. RVM will helps us to manage different ruby and gems version in a same system
2. All required gems should be maintained through Gemfile, it will be useful when the time of deployment
3. You have to understand, learn and change the file route.rb
4. .rhtml is no longer in use, try to use either .html or .html.erb [I have created a script for this, let me know if any one wants] Note: .html.erb is the recommended extension
5. Need to use <%= yield %> instead of <%= @content_for_layout %> in layout
6. Here after all js, css and images are referred from ‘assets’ at /app directory instead of /public. and we can’t use /images/omie.gif here , need to use /assets/omie.gif in all of the places where we are referring images like <img> , css etc.,
7. Have to change pagination usage
@rss_pages, @rss_articles = paginate(:rss_articles, :order => "published_date DESC", :conditions => ["publication_string = ? ", "NEJM" ])
to
@rss_articles = RssArticle.paginate(:page => params[:page], :order => "published_date DESC", :conditions => ["publication_string = ? ", "NEJM" ])
Note: paginate will return only one object instead of two like what we have in our old (1.2.1) method, you can use the same object to get about page information, like @rss_articles.current_page, @rss_articules.next_page
In your old method you might uses, @rss_pages.current.next, here it is simple @rss_articles.next_page
8. Have to change paginate_by_sql
In your older method you might hacked the code in your application controller, but here the gem ‘will_paginate’ will do all of the required things for us. But of-course the usage of paginate_by_sql is bit different, look at our old method
@sql = “select * from lab_tests”
@unreviewed_pages,@labs_unreviewed = paginate_by_sql(LabTest, @sql,25)
but now we need to use as:
@labs_unreviewed = LabTest.paginate_by_sql(@sql,{:page => page, :per_page => 25})
9. use the function 'raw' to avoid HTML encoding
<% a= “<div> Test </div>” %>
<%= a %>
The output will be a html encoded like <div< Test </div>
<%= raw a %>
The output like what you expected <div> Test </div>
10. All session values (> 4kb) must maintain only through active_record_store [We can setup it through config/initializers/session_store.rb] before it is done directly in environment.rb and this one is optional in lower version.
Note: Rails 3 uses a newer version of session schema, need to remove our old one and have to migrate the newer one.
11. We can’t use render(:layout=>false) in viewer, of-course it is meaningless but some of us used in some of our old view pages (like /comp/_datepicker.rhtml) by our old developers. :p
12. request.url is enough instead of request.request_uri
13. request.env in enough instead of @request.evn to get environment keys
14. We need special plugins to use ‘act_as’ modifiers such as acts_as_list, acts_as_tree.
it is under in review, as per my current knowledge , we have to use ‘ancestry’.
ref: https://github.com/stefankroes/ancestry
rails plugin install acts_as_tree => but it raises error. need to review about it
15. DateTime is no longer work, use Time always
16. There is no remote tag , use remote specifier as argument with the helper
Say for eg:
We used link_to_remote, form_remote_tag remember ?? this is going to be just
link_to, form_tag
so the code
link_to_remote("Next",{:update => "unreviewed_block"}) become
link_to("Next",{:update => "unreviewed_block", :remote => true})
and the form_remote_tag code
<%
form_remote_tag(
:update => "_results_",
:url => {:controller => '/chart/demo', :action => 'add_quick_link_refs',:id => 'link_ref'}
)
%>
Other HTML code here
<% end_form_tag %>
becomes
<%
form_tag(
:update => "_results_",
:url => {:controller => '/chart/demo', :action => 'add_quick_link_refs',:id => 'link_ref'},
:remote => true
) do
%>
Other HTML code here
<% end%>
Still there exists more.. will try to update if possible.
Comments
Post a Comment