Tudor Lupei
2010-Jun-11 18:03 UTC
How do I pass interpolation variables to AR validations?
(Rails 2.3.8)
Say I have in config/locales/en.yml:
en:
activerecord:
attributes:
foo:
bar: ''Long%{br}name''
Now, in HTML I can do:
t(:''activerecord.attributes.foo.bar'', :br =>
''<br/>'')
and in LaTeX:
t(:''activerecord.attributes.foo.bar'', :br =>
''\\\\'')
However, this is doomed to fail with AR validations, e.g.:
# Model
class Foo < ActiveRecord::Base
validates_presence_of :bar
end
# View Error
I18n::MissingInterpolationArgument in Foo#create
missing interpolation argument in "Long%{br}name"
({:count=>"1"} given)
So how do I pass :br to ''activerecord.attributes.foo.bar'' in
the context
of Foo?
Or is my approach wrong altogether?
Thank you
--
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Tudor Lupei
2010-Jun-12 07:44 UTC
Re: How do I pass interpolation variables to AR validations?
Got this working by using Ruby hashes instead of YAML:
{
:en => {
:activerecord => {
:attributes => {
:foo => {
:bar => lambda {|scope, opts| "Long#{opts[:br] || ''
''}name" }
}
}
}
}
}
--
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.