Upgrading RailsPlugins.org to Rails 3 - Part 1
Tue May 18 04:34:07 -0700 2010
Note, this post has been recreated now that Rails 3 has been released. Please see: Updating Railsplugins.org to Rails 3
New version available
Please see the above new version, the below is old content and not really usable any more
Old content:
I am going to do a series of blog posts covering the upgrade of RailsPlugins.org to Rails 3. You can follow along as we go and comments or suggestions are welcome!
This upgrade was done using at least Rails 3 beta3. If try it on anything earlier, it will most likely go boom.
Process
Going about upgrading a non trivial site like RailsPlugins.org requires a process to make sure it works:
- Confirm the gems and plugins you are using either work with Rails 3, there are alternatives you can use, or you are interested in helping upgrade them – this is the most important step in terms of scope and time required to get the job done.
- Run all specs and features or tests and make sure they pass – if you don’t have any, then now would be a good time to install Cucumber and write at least features covering all the main user stories of your site.
- Run the rails_upgrade plugin to highlight areas of concern
- Upgrade the application to Rails 3
- Fix all concerns within your application itself, ignoring plugins for now
- Go through each plugin and gem, either installing newer versions that are Rails 3 compatible, or replacing / fixing them
- Run all specs and features and tests and make sure they pass
- Boot up and play around in your development environment
- Deploy on a staging environment to confirm your upgrade
- Deploy live and watch like a hawk.
I am going to document all these steps as part of upgrading the RailsPlugins.org site.
Confirm the gems and plugins you are using
Going through all the plugins and gems we use on the RailsPlugins.org site, showed up that most of them have Rails 3 versions available or listed as “Maybe”. I guess I’ll be helping people get it done! :)
Run all specs and features
I have good coverage on RailsPlugins.org and it is all green… so onward and upwards.
Run the upgrade plugin
The rails_upgrade plugin is hosted on github and up to date with all the latest bells and whistles of Rails 3, so we’ll use that:
$ script/plugin install git://github.com/rails/rails_upgrade.git
And then once installed, we do:
$ rake rails:upgrade:check
Which gives us pages of output, simplified down to:
Deprecated constant(s) Constants like RAILS_ENV, RAILS_ROOT, and RAILS_DEFAULT_LOGGER are now deprecated. More information: http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/ ... Deprecated session secret setting Previously, session secret was set directly on ActionController::Base; it's now config.secret_token. More information: http://weblog.rubyonrails.org/ ... Old session store setting Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever. More information: http://weblog.rubyonrails.org/ ... Deprecated ActionMailer API You're using the old ActionMailer API to send e-mails in a controller, model, or observer. More information: http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3 ... Old ActionMailer class API You're using the old API in a mailer class. More information: http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3 ... Soon-to-be-deprecated ActiveRecord calls Methods such as find(:all), find(:first), finds with conditions, and the :joins option will soon be deprecated. More information: http://m.onkey.org/2010/1/22/active-record-query-interface ... named_scope is now just scope The named_scope method has been renamed to just scope. More information: http://github.com/rails/rails/commit/d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914 ... Old Rails generator API A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators). More information: http://blog.plataformatec.com.br/2010/01/discovering-rails-3-generators/ ... Old router API The router API has totally changed. More information: http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/ ... Deprecated ERb helper calls Block helpers that use concat (e.g., form_for) should use <%= instead of <%. The current form will continue to work for now, but you will get deprecation warnings since this form will go away in the future. More information: http://weblog.rubyonrails.org/ ... New file needed: config/application.rb You need to add a config/application.rb. More information: http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade ...
OK, so this might be too long for a single blog post, let’s take it in sections then.
Deprecated constant(s)
This section produced the following output:
Deprecated constant(s) Constants like RAILS_ENV, RAILS_ROOT, and RAILS_DEFAULT_LOGGER are now deprecated. More information: http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/ The culprits: - /Users/mikel/Code/railsplugins/lib/tasks/environments.rake - /Users/mikel/Code/railsplugins/lib/tasks/cucumber.rake - /Users/mikel/Code/railsplugins/lib/tasks/hoptoad_notifier_tasks.rake - /Users/mikel/Code/railsplugins/lib/tasks/rspec.rake
Which doesn’t seem too bad. I only really have one file in my application that is to blame, environments.rake, the other three are part of plugins that RailsPlugins.org uses, and I trust that the Rails 3 versions of these which we will update to later, should handle themselves.
Opening up environments.rake we see:
# Sets environments as needed for rake tasks
%w[development production staging].each do |env|
desc "Runs the following task in the #{env} environment"
task env do
RAILS_ENV = ENV['RAILS_ENV'] = env
end
end
task :testing do
Rake::Task["test"].invoke
end
task :dev do
Rake::Task["development"].invoke
end
task :prod do
Rake::Task["production"].invoke
end
This is a custom rake file we use to easily set environments for rake tasks. However, setting RAILS_ENV is deprecated in Rails 3. In Rails 3, you can set Rails.env directly with an assignment. So changing this rake task to be Rails 3 compatible would be:
# Sets environments as needed for rake tasks
%w[development production staging].each do |env|
desc "Runs the following task in the #{env} environment"
task env do
Rails.env = env
end
end
task :testing do
Rake::Task["test"].invoke
end
task :dev do
Rake::Task["development"].invoke
end
task :prod do
Rake::Task["production"].invoke
end
OK good. As I mentioned above, we are going to eave the cucumber, rspec and hoptoad files to be updated by their respective gems as we move along.
Deprecated session secret setting
The rails_upgrade plugin has pointed out the following:
Deprecated session secret setting Previously, session secret was set directly on ActionController::Base; it's now config.secret_token. More information: http://weblog.rubyonrails.org/ The culprits: - /Users/mikel/Code/railsplugins/config/initializers/session_store.rb Old session store setting Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever. More information: http://weblog.rubyonrails.org/ The culprits: - /Users/mikel/Code/railsplugins/config/initializers/session_store.rb
Which looks like this:
config/initializers/session_store.rb
ActionController::Base.session = {
:key => ‘_plugins_session’,
:secret => ‘somereallylongrandomkey’
}
In Rails 3, this process was changed quite significantly, with this commit, the upgrade though is very straight forward. First, you reduce session_store.rb to the following:
Rails.application.config.session_store :cookie_store, :key => "_my_app_name_session"
And then, because we now need somewhere to store the secret, you create a new file called config/initializers/cookie_verification_secret.rb and put inside of it:
Rails.application.config.cookie_secret = 'somereallylongrandomkey'
If instead of using cookies, you were using active record as the store, then you obviously wouldn’t need the cookie_verification_secret.rb file and instead would insert any other config you needed into its own file inside of initializers.
This gives us the added bonus of being able to exclude cookie secrets from source control systems.
In the next instalment, we’ll cover getting the RailsPlugins.org site actually up and running on Rails 3.
blogLater
Mikel




Tue May 18 20:12:51 -0700 2010
The Drink Rails blog picked this post as one of the top ruby on rails blogs of the day.
Tue Oct 12 17:17:37 -0700 2010
Mickel,
I’m upgrading my application to rails 3. I did the following:
(1) I converted ActionController::Base.session = { :key => ‘_my_site’ } into Rails.application.config.session_store :cookie_store, :key => “_my_site”, and stored this in file “config/initializers/session_store.rb”.
(2) I converted ActionController::Base.session = { :secret => ‘my_session_secret_key’ } into Rails.application.config.cookie_secret = ‘my_session_secret_key’ and stored this in the file “config/initializers/cookie_verification_secret.rb”
(3) In my existing file “cookie_verification_secret.rb”, there was a ActionController::Base.cookie_verifier_secret = ‘my_verifier_secret’. I tried converting this into (a) Rails.application.config.secret_token = ‘my_verifier_secret’, and (b) MySite::Applicatin.config.secret_token = ‘my_verifier_secret’. In both cases, I kept getting the error “ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken)”, when I tried to delete an object (an existing post). I also placed the <%= csrf_meta_tag %> in my layout but it does not help. Do you have any suggestion?
Tue Nov 08 19:41:52 -0800 2011
I have not upgraded at this point. I am a bit nervous that all will work out well. I will probably do it first on my production machine and then go from there. I would be interested in hearing of others who have made the leap.
Tue Jul 19 00:31:05 -0700 2011
OK, I have made this upgrade but now I am getting some errors and don’t know what to do :(
Mon Aug 01 11:37:04 -0700 2011
I have not upgraded at this point. I am a bit nervous that all will work out well. I will probably do it first on my production machine and then go from there. I would be interested in hearing of others who have made the leap.
Mon Aug 08 02:41:17 -0700 2011 Great to read more articles from your side. No doubt it’s really a great article and I felt really great going through your blog post.
Sat Sep 24 16:11:40 -0700 2011
I am thinking about using a cloud computing host to host my websites. Will there be any problems with my websites when I migrate them over to the cloud hosting? I don’t want the new Rails plugins to cause any glitches during the migration. Thanks!
Tue Jan 10 02:40:24 -0800 2012
In most languages, local variables are automatic variables stored on the call stack directly. This means that when a recursive function calls itself, local variables in each instance of the function are given separate memory address space. Thanks.
Regards,
Personal statement services review
Wed Jan 11 00:55:17 -0800 2012
In programming languages with only two levels of visibility, local variables are contrasted with global variables. On the other hand, many ALGOL derived languages allow any number of levels of nested functions with private variables, functions, constants and types hidden within them. Thanks a lot.
Regards,
Douglasville bankruptcy attorneys
Fri Jan 13 06:15:25 -0800 2012
sh
Sun Jan 15 22:35:53 -0800 2012
The ergonomics of a program: the ease with which a person can use the program for its intended purpose, or in some cases even unanticipated purposes. Such issues can make or break its success even regardless of other issues. Thanks a lot.
Regards,
Winfield Estate
Thu Jan 19 21:49:04 -0800 2012
The amount of system resources a program consumes the less, the better. This also includes correct disposal of some resources, such as cleaning up temporary files and lack of memory leaks. Thanks a lot.
Regards,
James Wilson Morrice
Tue Jan 31 01:36:05 -0800 2012
The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors. The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic. Thanks.
Regards,
cv help