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

后端 未结 2 577
我在风中等你
我在风中等你 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: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 %>
      
      <% @in_completed_tasks.each do |task| %>
    • <%= check_box_tag "task_ids[]", task.id %> <%= task.name %>
    • <% end %>
    <%= submit_tag "Submit your Answers" if @in_completed_tasks.present? %> <% end %>

提交回复
热议问题