0

當我訪問的頁面,我得到一個錯誤。引發ArgumentError在ContactsController#新

錯誤的參數數目(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 => "[email protected]", 
     :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 
+2

什麼**錯誤**你會得到?請發佈完整的堆棧跟蹤。 – mudasobwa

+0

錯誤的參數數量(1代表2) –

+0

「錯誤的參數數量(1代表2)」 - 絕不意味着堆棧跟蹤。 – mudasobwa

回答

1

model.rb線4條,你忘了添加 ''。這應該是attribute :message,

+0

現在我在這個行的「屬性:暱稱,:驗證碼=>真」的語法錯誤,意外的tSYMBEG,期待keyword_do或'{'或'('屬性:暱稱,:captcha = > true ^ –