A line of my of code is as follows:
validates :price, :numericality => {:greater_than_or_equal_to => 0.01}
:price
is the only symbol that I defined. :numericality
and :greater_than_or_equal_to
both have some meaning of comparison.
Symbols are like strings. They sometimes are used in constructions that look like method invocations, but they are not methods.
In your case, method validates
accepts two parameters, a symbol and a hash. :numericality
and :greater_than_or_equal_to
are just keys in a hash, nothing more. What will validates
do with them, no one knows (except validates
itself). So, in order to find out, you need to read documentation on validates
(and related rails guides, maybe).
The webpage here http://guides.rubyonrails.org/active_record_validations_callbacks.html should show what validations are available.
The symbols you refer to don't have a 'meaning' per se, but tell the methods what to do when passed as variables.
Validates is simply a method call, but in ruby the parentheses are option, sometimes putting them in makes it easier to conceptualise it, such as
validates(:price, :numericality => {:greater_than_or_equal_to => 0.01})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.