Pages

Thursday, October 17, 2013

Difference b/w Rails 2 and Rails 3

Now a days Rails 3.2 version is going on. I am going to write some difference between in Rails 2.x and 3.x.

1. Some command line syntax has been changed in Rails 3.x like as
  •  rails generate instead of rails script/generate
  •  rails server instead of ruby server
 2. Introduction of bundler (New way to manage your gem dependencies)
       - Rails 3.x has bundle concept (Gem File) while Rails 2.x does not have

New features in Rails 4

Introduction:
Finally, the most awaited Rails 4.0 version has been released by the Rails team on 25th of June. Rails 4 has got huge changes. There are tons of new features available, which can make your life as a Rails developer a lot easier.  We will talk about the most exciting features in Rails 4 and why you should upgrade from Rails 3 version as soon as possible.
New features of Rails4
 1.  Ruby Versions
It is essential to note that Rails 4 would require Ruby 1.9.3 or higher, in fact Ruby 2.0.0 is recommended for your Rails 4 apps.

Observers in Rails 3

Rails observers are sweet, You can observe multiple models within a single observer
First, you need to generate your observer:

rails g observer Auditor

Then, in your fresh auditor_observer.rb file define the models you wish to observe and then add theafter_create callback.

class AuditorObserver < ActiveRecord::Observer
   observe :model_foo, :model_bar, :model_baz

   def after_create(record)
    #do something with `record`
   end
end