Rails‎ > ‎

Rails - routing

The URL in rails has a meaning.
The default template is :


  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'


This means that if I want to have a book library (for example), I can do the following method :

... LibraryController ...

def book
    Book.find(params[:id])
end

When the URL is

http://localhost:3000/library/book/123

The thing to note here is that the ID appears as a param by default - since it is in the URL.


Comments