语法错误,意外的'{',期待keyword_end

时间:2015-03-18 01:23:46

标签: ruby-on-rails ruby

在以下代码中出现以上错误:

class User < ActiveRecord::Base
    validates :name, :email, :username, :password, presence: true { message: "All fields are required. Please try again." }
    validates :age, numericality: { greater_than: 18, message: "Your might be 18 or older to use this app." }
    validates :email, uniqueness: true { message: "This email address is already taken. Please login instead." }
    validates :username, uniqueness: true { message: "This username is already taken. Please try again." }
    validates :password, length: { minimum: 6, too_short: "%{count} characters is the maximum allowed" }        
end

1 个答案:

答案 0 :(得分:1)

您使用过的每个地方something: true { ... }都是语法错误。你不能在那里放true

validates :name, ..., presence: true { message: "All fields are required. Please try again." }

需要

validates :name, ..., presence: { message: "All fields are required. Please try again." }