在 haml 表单上发布数据并放置路由错误

Posting data on haml form and put routing error

我有一个演出表格,想添加一个表格来编辑它,以便用户可以输入票证 ID。我最初在控制器中将其修改为编辑操作,但后来将其更改为更新。当我单击提交按钮时,我收到一条错误消息,显示 "No route matches [PUT]",我觉得我好像错过了某处的一步。

edit.html.haml

= form_for [:admin, @diagnostic], url: edit_admin_diagnostic_path do |f|
    .field
        = label_tag :ticket_id
        = text_field_tag "ticket_id"
        = submit_tag "Submit", method: :put, data: { confirm: "Are you sure?" }

    .field
        = link_to 'show', admin_diagnostic_path

diagnostics_controller

class Admin::DiagnosticsController < Admin::BaseController

  before_filter :diagnostic, only: [:show, :delete, :edit, :update]

  def index
    @diagnostics = DiagnosticInfo.all.order_by(:created_at.desc).page(params[:page]).per(50)
  end

  def show
    respond_to do |format|
      format.html
      format.json { render json: @diagnostic }
    end
  end

  def update
   @diagnostic = DiagnosticInfo.find(params[:id])
    if allowed.empty?
      render action: "edit", error: 'Un-allowed attribute update request!'
    elsif @diagnostic.update_attributes(allowed)
      redirect_to admin_lessons_url, notice: 'Lesson was successfully updated.'
    else
      render action: "edit"
    end
  end


  end

  def destroy
    diagnostic.destroy
    redirect_to admin_diagnostics_path
  end

routes.rb的相关部分

  resources :diagnostics, only: [:index, :show, :destroy, :edit, :update] do 
      put 'ticket_id', on: :collection
    end

据我所知,表单参数应该是:

= form_for [:admin, @diagnostic], url: admin_diagnostic_path(@diagnostic) do |f|

不是edit_admin_diagnostic_path

在您寻找 put/patch

时,

edit_admin_diagnostic_path 将前往 get admin_diagnostic 的编辑页面

在您的情况下,您正在尝试将 put 请求发送到 .../edit url,这显然不存在,因此出现此错误。