Here I will share some of the interesting ruby features that you will notice when looking into mature ruby code by advanced level coders.
while I.am_alive? do
read.think.innovate.share
I.wannabe_alive += 1
end
Thursday, November 11, 2010
Wednesday, November 10, 2010
Upgrading to Ruby on Rails 3 - beware!
Ryan Bates had a series of posts (1, 2 and 3) on upgrading your Rails 2.3.x apps to Rails 3.x and sure they are useful. But if you are really doing that, beware of the following changes that you will need to do. It will take a lot of time for sure if you you have a moderate sized app.
Upgrading your models:
Upgrading your models:
- Get rid of all validates_xxx_of with appropriate validates
- Get rid of all def validate ... end methods with custom validator
- Find out all occurrences of :conditions, :limit, :order and use new active record methods instead
- Replace all named_scope with scope
- Make sure your acts_as_xxxx plugins are all updated to use Ruby on Rails 3. I had troubles with Authlogic as it shows Based.named_scope is DEPRICATED. Still looking for a solution.
- Ruby 1.9.2 doesn't work with soap42 wsdl driver. Haven't found a solution yet as it keeps reporting an error regarding "XML processor module" missing.
Upgrading your controllers:
- Find out all occurrences of find method and replace with where.
- Find out all calls to Mailer that looks like deliver_xxx and make it xxx.deliver
Upgrading your views:
- All erb blocks must start with a has to be changed to . Do the same for all such erb blocks with a do.
- All link_to_remote or remote_form_for or other remote form helpers need to be changed to their non-remote counterparts with a param :remote => true.
Upgrading your mailers:
- body method is gone, instead of the hashed params to this method, just define instance variables.
- All xxx.text.html.erb now becomes xxx.html.erb in the mailer views.
Upgrading the config files:
- The best way is to crate a new rails app and then copy the config folder into yours.
- Look at the initializers and clean up any required initializers.
- Make sure you have autoload_paths setup to include the lib folder. It is not included by default, so your code from the lib folder won't be accessible.
- Look at deprecation warning and you will see lots of config.action_controller.* need to changed to config.*
Plugins:
- All plugin/lib/rails/tasks/*.rake needs to be copied in to plugin/lib/tasks/*.rake
- Make sure your plugins don't use named_scope, if you find any, replace with scope.
- Whatever applies to your models should also be applied to your plugins that act on models.
Testing:
- Check you have updated shoulda, rspec or whatever lib you use.
- Update test codes according to your new lib.
Upgrading IDE to use RVM:
- Your IDE is not smart enough to use RVM. However use this to get TextMate ready.
Subscribe to:
Posts (Atom)