Reputation: 11830
How is it possible to use hyphen in resources urls?
For example: /my-model/
or /my-model/1
.
If I define route as resources :"my-model"
I get syntax error because rails generates method def hash_for_my-models_url(options = nil)
.
Upvotes: 10
Views: 2362
Reputation: 11830
I have found the solution:
resources "my-models", :as => :my_models, :controller => :my_models
UPDATE:
As Timo Saloranta said in comment it works without :controller => :my_models
in latest Rails 3 versions.
Upvotes: 14
Reputation: 47548
You can use the :as
option to configure resourceful routes with hyphenated URLs:
map.resources :my_model, :as => "my-model"
results in
my_model_index GET /my-model(.:format) {:action=>"index",
:controller=>"my_model"}
...etc...
Upvotes: 2
Reputation: 1721
Have you tried a custom route?
map.connect "/my-model/:id", :controller => 'my-model-controller', :action => 'read'
This would invoke the 'read' method of 'my-model-controller.rb'.
Upvotes: 0