Ruby on Rails
Monday, July 28, 2014
On Friday, 25 July 2014 23:21:08 UTC-4, Ricky Hopkins wrote:
I am trying to convert an integer to a DAYNAME in my validation message
validates_uniqueness_of :day, scope: :store, :message => "already has a target for #{Date::DAYNAMES[self.day]}."
This does not seem to work, I cannot access the day value.The following displays the correct value
validates_uniqueness_of :day, scope: :store, :message => "already has a target for %{value}."
This throws an error:
validates_uniqueness_of :day, scope: :store, :message => "already has a target for #{Date::DAYNAMES[%{value}]}."
Using double quotes with #{} will *definitely* not do what you want; the interpolation will be attempted at class-load time, not when the string is needed.
The value passed to :message is handed off to I18n.translate, so the docs for that may be some help.
It may be easier (and clearer) to just define a custom validation function that does what you want.
--Matt Jones
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/88db0d14-0e46-40a2-92f6-bd57af88496f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment