Rails 4 Validation: where to put the allow_nil when doing an inclusion? -
are these 2 implementations functionally equivalent? if so, "better?"
# model widget_colors = %w(red yellowish green) validates :widget_color, inclusion: {in: widget_colors, allow_nil: true} or
# model widget_colors = %w(red yellowish green) validates :widget_color, inclusion: {in: widget_colors}, allow_nil: true update: fixed typo illustration reads validates
firstly validate , validates different methods - should validates here.
validates search supplied hash so-called _validates_default_keys, internal array [:if, :unless, :on, :allow_blank, :allow_nil , :strict]. arguments passed validates beingness in array treated mutual options validators attached model method. if do:
validates :widget_color, inclusion: {in: widget_colors}, uniqueness: true, allow_nil: true allow_nil impact both of validators, or equivalent of:
validates :widget_color, inclusion: {in: widget_colors, allow_nil: true}, uniqueness: {allow_nil: true} on other hand with
validates :widget_color, inclusion: {in: widget_colors, allow_nil: true}, uniqueness: true it impact validator defined (in case inclusionvalidator)
ruby-on-rails validation inclusion
No comments:
Post a Comment