John Smith John Smith - 2 years ago 66
Ruby Question

No route matches [PUT]. How to correctly route?

I have this code for my _form.html.haml:

= form_tag edit_work_flows_path, :method=> 'put' do |f|
-@all_configurations.each do |config|
-if config.configuration_key == 'DUPLICATE_CLAIM_WI_MANAGER'
=hidden_field_tag "config_ids[]",
%label= t('workflow.duplicate_claim_manager')

It is giving the error that "No route matches [PUT]"

However, when I change the form_tag to
it works. But it doesn't go to the page I want. I want it to go to the edit_work_flows_path page. Here is my route:

scope '/settings' do
resource :app_configurations, only: [:edit, :update] do
collection { get 'cover_letter_template' }
resource :work_flows, only: [:edit, :update]

Any idea how to fix this?

Answer Source

No route matches [PUT]

The problem is with your form_tag. When you run rake routes, you will see like the below

   Prefix Verb  URI    Pattern                   Controller#Action
edit_work_flows GET   /work_flows/edit(.:format) work_flows#edit
     work_flows PATCH /work_flows(.:format)      work_flows#update
                PUT   /work_flows(.:format)      work_flows#update

This means the edit_work_flows_path can only accept GET, that is why you got the error. You should change edit_work_flows_path to work_flows_path. The below code should work.

= form_tag work_flows_path, :method=> 'put' do |f|
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download