Rails nested URL question
Im having issues with RESTful URLs in Rails.
I have site.com/services url, and I want to have subpages under that category, thats it: site.com/services/arquitecture, site.com/services/plumbing, etc.
The pages that im serving under that category are "static" .rhtml files and I would want them to be on the same controller.
Is there a 开发者_JS百科way of doing this? I've tried nested resources but I find it hard to fully understand.
Thanks
Resources weren't built for serving static pages. Use regular, non-RESTful routes where you can define exactly which URLs maps to which controller and action.
Here is one simple approaches for this.
Assuming you have a "services" resource in your routes.rb, you don't need nested resources - just add a :members hash to your route definition:
map.resources :services, :member => {:plumbing => :get, :arquitecture => :get, ...}
then define empty actions in your services controller for each static page. You can use page caching for those pages if they are truly static & Rails will bypass the controller altogether after the 1st call to each action.
精彩评论