Md Sirajus Salayhin
Md Sirajus Salayhin

Reputation: 5144

Change resource route name

Hou could I change resource name without changing resource URL.

Explanation:

My resource route is resources :universities

So my routes are new_university_path or universities_path

Now I have changed my resource name to departments as follows:

resources :departments, :controller => :universities 

But problem is when I run rake routes I found that my URL has already been changed. So I like a solution where after changing my resource name my routes are works as before, like new_university_path or universities_path

Is this possible in rails 3 ?

Upvotes: 1

Views: 815

Answers (2)

K M Rakibul Islam
K M Rakibul Islam

Reputation: 34336

You should be able to do that by using naming routes by giving it the name you want for that route in :as option:

resources :departments, :controller => :universities, :as => :universities

Upvotes: 1

bryanmikaelian
bryanmikaelian

Reputation: 86

You can add:

resources :departments, :controller => :universities, :as => :universities

That should keep the URL helpers the same.

Upvotes: 4

Related Questions