ruby on rails - Is there a way to automatically create a plural route for index and singular for everything else? -


when dealing collection resource, use plural index (ie. list) page (viewing many objects), , singular other pages (create/update/delete 1 object).

in order so, seem have create routes so:

map.objects 'objects.:format', :controller => :object, :action => :index, :conditions => { :method => :get } map.resources :object, :controller => :object, :except => :index 

this creates routes so:

     objects    /objects(.:format)          {:action=>"index", :controller=>"object"} object_index post   /object(.:format)           {:action=>"create", :controller=>"object"}   new_object    /object/new(.:format)       {:action=>"new", :controller=>"object"}  edit_object    /object/:id/edit(.:format)  {:action=>"edit", :controller=>"object"}       object    /object/:id(.:format)       {:action=>"show", :controller=>"object"}              put    /object/:id(.:format)       {:action=>"update", :controller=>"object"}              delete /object/:id(.:format)       {:action=>"destroy", :controller=>"object"} 

it works, seems i'm using line in routes file (to explicitly specify index route) when shouldn't have to. there way want in 1 route? or, alternately, there reason not route way?

restful routing designed in such way you're scoping down want do. go http://example.com/objects. here, you're telling site want list objects.

now when go http://example.com/objects/2 you're telling want see object identifier of 2 in list (or resource) of objects.

finally, when go http://example.com/objects/2/edit you're saying want find object again identifier of 2 time edit rather view it.

by going against grain have suggested in routing helpers causing tremendous amount of unnecessary pain , else reading code.

however if choose go path (again, advise against it) yes, defining 2 routes way.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -