Help solving a routing error in Rails
-
05-07-2019 - |
Question
I have a controller called form_questions_answers
with a method in it called modify_rule
but when I perform a post to /form_questions_answers/modify_rule/60
Rails tells me:
Routing Error
No route matches "/form_questions_answers/modify_rule/60" with {:method=>:post}
Why is this happening, I have map.resources :form_question_answers
in routes.rb, and map.connect ':controller/:action/:id'
at the bottom of the routes.rb file, so why isn't the modify_rule
action being triggered?
Solution
/form_questions_answers/modify_rule/60
would not accept POST on a map.resources basis. It would either be a GET or a PUT in line with REST.
You might want to take a look rails routing guide for some info on routes.
Happy turkey day!
OTHER TIPS
If you're using resource based routes you probably want to remove the default routes. That said you probably want to add a new member to your form_question_answers
route like this:
map.resources 'form_questions_answers', :member => { :modify_rule => :post }
You can read more about adding options to your routes here.