I’m new to Ruby on Rails and trying to learn the framework by reading Rails 3 in Action book as well as looking into different online resources. But now I’m struggling with dramatic syntax difference in what book explains, what I see in online resources and what I see in generated code. For example, I’d like to setup my custom routes in routes.rb
The book says
match '/login',
:to => "accounts#login"
Online resource says:
map.login '/login', :controller => 'accounts', :action => 'login'
Another online resource says:
match '/login' => 'accounts#login', :as => 'login'
In my case works only the last one… So the question is why syntax is so different and where to look for syntax explanation for the latest Ruby on Rails?
The first example is fine and is essentially the same as the third example. It just doesn’t set up the login paths for you e.g. in your code you won’t be able to reference login_path like you can with the third example (the :as => ‘login’ tells rails to set up the login_path helper).
The online resource (second example) is for Rails v.2.3.11 which is fairly old – we’re now on v.3.2. so that resource is out of date. Here is the up to date version.