【问题标题】:Rails, param is missingRails,参数丢失
【发布时间】:2016-01-10 19:35:10
【问题描述】:

当我尝试保存时,我得到了错误。

参数丢失或值为空:帮助

我的错误在哪里?我第一次看到这个错误

我的application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  def authenticate_admin_user!
    authenticate_user!
    redirect_to root_path unless current_user.admin?
  end

  def help_request
    @help = Help.new(help_params)
    if @help.save
      redirect_to root_path
    else
      #
    end
  end

  private

  def help_params
    params.require(:help).permit(:name, :email, :messages)
  end
end

和我的部分_help_request.html.slim

div id="help_request"
  h1 Help form
  hr
  = form_for Help.new, as: :post, url: help_request_path do |f|

    = f.label :name
    br
    br
    = f.text_field :name, class: 'form-control',
                          placeholder: 'your name'

    = f.label :email
    br
    br 
    = f.text_field :email, class: 'form-control',
                           placeholder: 'your email'

    = f.label :messages
    br
    br 
    = f.text_area :messages, class: 'form-control',
                             placeholder: 'your message'
    br
    br
    = f.submit 'Send', class: 'btn btn-primary'

【问题讨论】:

    标签: ruby-on-rails ruby model params


    【解决方案1】:

    我认为这是因为您的表单声明中出现了as: :post。似乎存在params[:post],但不存在params[:help]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多