0

Ich erhalte eine Fehlermeldung, wenn ich die Seite besuchen: localhost:3000/contacts
Argument in ContactsController # neuen

Die Fehler, die Details und die Quellcode ist unten angegeben.

falsche Anzahl von Argumenten (1 2)

Extrahierte Quelle (Strecken Linie # 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 

-Code für Controller

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

Was ** Fehler ** erhalten Sie? Bitte posten Sie einen kompletten Stack-Trace. – mudasobwa

+0

falsche Anzahl von Argumenten (1 für 2) –

+0

"falsche Anzahl von Argumenten (1 für 2)" - ist keineswegs ein StackTrace. – mudasobwa

Antwort

1

In model.rb Linie 4, vergessen Sie '' hinzuzufügen. Dies sollte attribute :message, sein

+0

Jetzt bekomme ich SyntaxError in ContactsController # Neu in dieser Zeile "Attribut: Nickname,: Captcha => True" und der Fehler ist Syntaxfehler, unerwartete tSYMBEG, erwartet Keyword_do oder '{' oder '(' Attribut: Nickname,: Captcha = > wahr ^ –