Change Routing Controller Action

I am afraid here with the problem: I have questions with controllers that have a new action. When I need to create a new question, I type

/questions/new 

What change to route.rb, I have to do to change the URI to

 /questions/ask 

Thanks. Valve

+4
source share
3 answers

Try the following:

 map.ask_question '/questions/ask', :controller => 'questions', :action => 'new' 

Then you will have a named route, and you can:

 link_to "Ask a question", ask_question_path 
+7
source

If you use RESTful routes, perhaps you would like to use map.resources for your questions.

To rename the action URLs, you can do this:

map.resources :questions, :path_names => { :new => 'ask', :delete => 'withdraw' }

(I added delete as an example)

+5
source

What version of rails?

Usually the default route should catch something like /: controller /: action, so you can simply create the ask method in your question controller. Take a look at the api documentation for named_route and map_resource if you need something smoother to work.

0
source

All Articles