I know how to already set nested resources in route files ... the question is how to do this, with the same payload and with fewer lines.
Let's say I have BlogSite . BlogSite has many Posts , but it also has many Authors and many Dates . (this may not be the best example, but carry me).
To make CRUD on Post , I want to be able to use
/blog_sites/1/author/2/date/3/posts
Thus, any of the filtering options may be optional in the URL. I know you can use something like
get (/blog_sites/:blog_id)(/author/:author_id)(/date/:date_id)/posts => "posts#index"
but I do not want to lose all the benefits of CRUD using nested resource routing. Currently, I have to duplicate most of the routing to get it working, and I'm looking for a better way to do this:
resources :blog_sites do resources :authors do resources :dates do resources :posts end resources :posts end resources :dates do resources :posts end resources :posts end
... and so on. It can become quite uncontrollable shallow quickly.
How can I support optional parameters while keeping .rb DRY and reasonable routes?
source share