I don't know how to pass many arguments to before_validation hook. I
want to implement the hook on both create and update methods:
before_validation(:on => [:create, :update]) {
// do something
}
But this form of arguments :on => [:create, :update] throws an error:
/active_support/callbacks.rb:403: syntax error, unexpected '[',
expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
... (self.validation_context == :[:create, :update])
This one :on => :create, :update also doesn't work:
syntax error, unexpected ')', expecting tASSOC
before_validation(:on => :create, :update) {
And API has only one example with one argument:
before_validation(:on => :create) do
self.number = number.gsub(/[^0-9]/, "") if
attribute_present?("number")
end
How to pass multiple arguments?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0873dace5e98892073621b1422d27818%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment