当我尝试保存时,我收到错误。
我错了吗?我第一次看到这个错误param丢失或值为空:help
我的 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'
答案 0 :(得分:1)
我认为这是因为您的表单声明中有as: :post
。似乎params[:post]
存在,但不是params[:help]
。