ActionController::RoutingError (No route matches [PUT] ) for ajax call

后端 未结 2 578
我在风中等你
我在风中等你 2020-12-22 00:47

Hope all is well.

I want to ajax call on _questions_form. It works without remote: true option, yet I am using actioncable

相关标签:
2条回答
  • 2020-12-22 01:12

    just remove the :method => :put that you have on your form, if you will create, it needs to be post, but just remove the method part, and it will work.

    thats because there is no route to /tasks with put method when you create it with resources

    0 讨论(0)
  • 2020-12-22 01:19

    Your routes.rb should generate a routing of

    PUT /tasks/complete mapped to TasksController#complete

    but your form is doing a

    PUT /tasks instead (from your log), so there's something wrong with the request (i.e. your form)

    Can you try the following:

    resources :tasks do   
       collection do
         post :complete
      end      
    end
    
    <%= form_tag complete_tasks_path, format: :js, method: :post, remote: true do %>
      <ul>
        <% @in_completed_tasks.each do |task| %>
          <li>
            <%= check_box_tag "task_ids[]", task.id %>
            <!--<input type="checkbox" name="task_ids[]" id="task_ids_" value="5">-->
            <%= task.name %>
          </li>
        <% end %>
      </ul>
      <%= submit_tag "Submit your Answers" if @in_completed_tasks.present? %>
    <% end %>
    
    0 讨论(0)
提交回复
热议问题