【发布时间】:2016-07-31 06:39:18
【问题描述】:
访问页面时出现错误:localhost:3000/contacts
下面提供了错误、详细信息和源代码。
参数数量错误(1 比 2)
提取的源代码(第 4 行附近):
2 attribute :name, :validate => true
3 attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
4 attribute :message
5 attribute :nickname, :captcha => true
model.rb
class Contact < ApplicationRecord
attribute :name, :validate => true
attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :message
attribute :nickname, :captcha => true
# Declare the e-mail headers. It accepts anything the mail method
# in ActionMailer accepts.
def headers
{
:subject => "HsbNoid",
:to => "iamhsb001@gmail.com",
:from => %("#{name}" <#{email}>)
}
end
end
控制器代码
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(conact_params)
@contact.request = request
if @contact.deliver
flash.now[:notice] = 'Thank you for your message. We will contact you soon!'
else
flash.now[:error] = 'Cannot send message.'
render :new
end
end
private
def conact_params
params.require(:contact).permit(:name, :email, :message)
end
end
【问题讨论】:
-
你得到了什么错误?请发布完整的堆栈跟踪。
-
参数数量错误(1 对 2)
-
“参数数量错误(1 对 2)”——绝不是堆栈跟踪。
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2