ruby - Rails 4 model formatting and hashes (really basic) -
i have basic validation in model:
validates :student_number, :presence => true, :length => { :maximum => 255 }, :uniqueness => true
so that? here's best guess, if kindly tell me i'm mistaken, i'd appreciate it.
validates
method. send symbol :first_name
, :presence => true
, is...a hash :presence
key , true
value?
except doesn't hash, @ least not according docs.
and :length => { :maximum => 255 }
same sort of entity (hash?) :presence => true
expects hash argument?
thanks assistance.
ruby allows drop parentheses , brackets if can infer locations itself; in case, rewrite code as:
validates(:student_number, { :presence => true, :length => { :maximum => 255 }, :uniqueness => true })
which method call, passing first argument attribute validate, , second argument validation options, hash.
note: explanation bit of simplification, validates bit more complicated in how handles arguments. see here more details on how works exactly.
Comments
Post a Comment