在使用此验证语法时,Rails似乎不允许我传递多个参数。在第一个参数之后,它总是有一个意外逗号的语法方法。
class Apartment < ActiveRecord::Base
geocoded_by :location
after_validation :geocode
has_many :image_attachments
validates_associated :image_attachments
accepts_nested_attributes_for :image_attachments
validates :location, presence: true
validates :description, presence: true
validates :price, :presence => true
,:format => { with: /^[0-9]+$/, message: 'must be a number' }
validates :longitude, presence: true
end
答案 0 :(得分:0)
错误的格式化(以及#34; unsexy&#34;)将逗号放在下一行的开头。
最好做...
validates :price, :presence => true,
:format => { with: /^[0-9]+$/, message: 'must be a number' }
......应该可以正常工作。
更一致的风格是当key是符号时,使用Ruby 1.9约定键/值。
validates :price, presence: true,
format: { with: /^[0-9]+$/, message: 'must be a number' }