在haml表单上发布数据并输出路由错误

时间:2015-04-08 11:05:16

标签: ruby-on-rails haml

我有一个节目表单,想要添加一个表单来编辑它,以便用户可以输入票证ID。我最初在控制器中修改了这个作为编辑操作,但后来改为更新。当我点击提交按钮时,我收到一条错误,上面写着"没有路线匹配[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

1 个答案:

答案 0 :(得分:0)

据我所知,形式论证应该是:

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

不是edit_admin_diagnostic_path

当您正在寻找edit_admin_diagnostic_path / get

时,

put将转到patch admin_diagnostic的编辑页面

在您的情况下,您尝试向put网址发送.../edit请求,这显然不存在此错误。