Updating your app to Rails2 - A few simple tips
Posted by Vince Wadhwani on Jan 12, 2008
I just started updating Buyindie to Rails2. I thought it would be a pain but it turned out to not be that bad. Mostly since I was starting from an app that worked with 1.2.6 and also because I heeded most of the deprecation warnings I ran into. There were a few that I neglected though and it required some quick and dirty fixes. I'm not advocating these as the best solutions -- there's always a better way, but if you run into trouble you can go through this list and perhaps it'll give you some ideas of things to check.
Of course, the best tool is the development log. If you don't use that when developing... well, I highly recommend you start. Another great tool is the console. If you get an error in the development log and you want to be sure it's really an issue, fire up script/console and confirm and refine your code there. Anyway, here are the things I did:
- Replace all start_form_tag instances with form_tag
- Replace all end_form_tag instances with </form>
- Update all your plugins.. many required changes to work w/Rail2
- If you've got a tagging plugin and your code borks on taggings_count, replace it with taggings.count
- If you're using javascript and your code borks on foo[id].attributes.bar, change it to foo[id].bar
- Replace any built-in pagination with the will_paginate plugin
- If you reference a specific version of rails in your environment.rb, you'll want to either update that for Rails 2.0.2 or comment it out (which will make your app use the latest version).
- And of course make sure you have added an appropriate line to your environment.rb to take care of the new cookie-based sessions
For the last step, an example would be:
config.action_controller.session = { :session_key => "_myapp_session", :secret => "sd130918DF33$4134617341df374613874619387418237950051393" }
I'm sure there are other things out there but these are the ones I've run into so far. If you've got other tips feel free to leave them below. Finally, here's a great link to a rake task which should help you out in updating!