Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hyphen resources in rails 3 routes

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).

like image 389
Andrey Kuznetsov Avatar asked Nov 02 '10 15:11

Andrey Kuznetsov


2 Answers

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.

like image 122
Andrey Kuznetsov Avatar answered Nov 09 '22 04:11

Andrey Kuznetsov


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...

like image 26
zetetic Avatar answered Nov 09 '22 03:11

zetetic