2016-10-11 7 views
0

を作成する引数の数が間違っ:連絡先#で問い合わせ#私はこのエラーを持っている

例外ArgumentErrorは、引数の

間違った番号(0を与えられたが、2を期待)を作成

それは私を見ますこの行は私の見解から

<%= @contact.errors.full_message.each do |message| %> 

私の作成メソッドはcontact_contr ollerは引数に

contact_controller.rb

def index 
    @contact = Contact.all 
    end 

    def create 
    @contact = Contact.new(contact_params) 
    if @contact.save 
     flash[:notice] = "Welcome" 
     redirect_to "/" 
    else 
     flash[:alert] = "You filled wrong the form" 
     render 'connection' 
    end 
    end 

を取っていないし、私は私のモデルから、それらのメッセージを表示するようになってる

contact.rb

validates :firstname, presence: true, length: { maximum: 30, minimum:2, 
    too_long: "30 characters is the maximum allowed.", too_short: "2 characters is the minimum allowed." } 

validates :lastname, presence: true, length: { maximum: 50, minimum:2, 
    too_long: "50 characters is the maximum allowed.", too_short: "2 characters is the minimum allowed." } 

VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i 
validates :email, presence: true, uniqueness: {message: "Email is already subscribed"}, length: { maximum: 40, minimum:7, 
    too_long: "40 characters is the maximum allowed.", too_short: "7 characters is the minimum allowed.",}, 
    format: { with: VALID_EMAIL_REGEX } 

validates :password, presence: true, length: { maximum: 30, minimum:6, 
    too_long: "30 characters is the maximum allowed.", too_short: "6 characters is the minimum allowed." } 

私はルビーが何を望んでいるのか理解していない。誰でも分かりますか?あなたはfull_messagesないfull_message

full_messageを使用する必要があります

+2

ではなく 'full_message'です...キーと略さメッセージを受け取り、それは二つの引数を必要とするので、それらを組み合わせた方法であり、 'full_messages'よりもtypoですか?実際には 'full_message'を望んでいないと思います –

答えて

2

@contact.errors.full_message(:sausage, 'is too dry') 
=> "Sausage is too dry" 
関連する問題