我有以下表單驗證的姓名和電子郵件:參數是丟失或爲空值的:接觸
validates :name, presence: true
validates :email, presence: true
在我的瀏覽器,它看起來像:
但是,當我提交以下表格時:
= simple_form_for @contact, :url => create_enquiry_path, :method => :post do |form|
= form.input :name
= form.input :email
= form.input :phone
= form.input :website
頁面沒有錯誤,但我得到:
param is missing or the value is empty for: contact
我的控制器:
def create
@contact = ContactForm.new(form_params)
if @contact.errors.any?
render :action => :new
flash[:error] = 'Please correct errors.'
else
redirect_to ....
flash[:notice] = 'Thank you for your message. We will contact you soon!'
end
private
def form_params
params.require(:contact).permit(:name, :phone, :email, :website)
end
可能有人請解釋什麼,我做錯了什麼?
'require(:contact)',但是在你的表單中沒有任何地方確實有':contact'字段。 – 2014-10-10 16:03:09
您還可以包含_console error_ logs嗎? – 2014-10-10 16:03:14
@MarcB,你建議將'@contact'改爲':contact'? – bootsa 2014-10-10 16:06:32