Section 6. RESTful Views
Using map.resources
cleans up routes.rb
and also enhances your views with several named routes. (For those of you who do not know, named routes are a rails feature that simplifies the URL generation process.) Instead of typing
link_to :controller => 'tasks', :action=> 'new'
we simply type
link_to new_task_url
The second line of code is simpler and more directly conveys the code’s purpose. Using map.resource
gives two different sets of helper methods, each of which has three variations. The first, outlined in Table 6.1, returns the path to a resource. The second set of methods, outlined in Table 6.2, provides automatic content type negotiation by attaching a format to the end of the URL. It accepts ...
Get Rails Refactoring to Resources: Using CRUD and REST in Your Rails Application now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.