File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -242,13 +242,17 @@ def validate(record)
242242
243243 class OptionsValidator < ActiveModel ::Validator
244244 def validate ( record )
245- unless record . options . is_a? ( Hash )
246- record . errors . add ( :options , message : "'options' is not an object" )
247- return
245+
246+ # Make sure to write an empty hash if options is nil
247+ if record . options . nil?
248+ record . options = { }
248249 end
249250
250- if record . options . empty?
251- record . errors . add ( :options , message : "'options' must include one or more valid options" )
251+ # Empty option hashes are allowed, so we skip further validation
252+ record . options . blank? && return
253+
254+ unless record . options . is_a? ( Hash )
255+ record . errors . add ( :options , message : "'options' is not a valid object" )
252256 return
253257 end
254258
You can’t perform that action at this time.
0 commit comments