Using Dashes for urls in ruby on rails
I have a view folder product_types. The name of the controller file is product_types_controller and the class I have is ProductTypesController. I'd normally keep the _ format that rails prefers but I need to keep the current page syntax for search index reasons.
How do I get this controller to show up for mysite.com/product-types and all pages in the folder product_types to appear for mysite.com/product-types/some-page? Do I need to name the pages with - or should I use the _ s开发者_如何学Goyntax as well and just change the routes.
This is for a Rails 2.3.8 site.
Thanks
For Rails 3 you have to do this differently:
resources "product-types", :as => :product_types, :controller => :product_types
In case you're using namespaces in your routes in Rails 3, you can use the following for dashes in urls:
namespace :product_types, :path => "product-types" do
If you're using RESTful routes, you can do this:
map.resources :product_types, :as => 'product-types'
I hope this helps!
In rails 3 you can do:
resources :product_types, :path => '/product-types'
精彩评论