在以下代码中出现以上错误:
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
答案 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." }