I need to pass in a variable to generate the label of a field with simple form. With normal translations you go about this in the following way: http://guides.rubyonrails.org/i18n.html#passing-variables-to-translations but for the life of me I am unable to get it to work with simple form.
I am attempting to pass it in using:
= f.input :name, :contact_type => f.object.contact_type.to_s
And in the simple_form.en.yml file:
en:
simple_form:
labels:
contacts:
name: "Name %{contact_type}"
This is outputting: Name %{contact_type}"
Ignoring the variable all together. Is there a way to accomplish this?
Thanks,
Ryan Lundie
You need to explicitly add the label to the form input like this :
= f.input :name,
:contact_type => f.object.contact_type.to_s,
:label => t(:'simple_form.labels.contacts.name', :contact_type => "Whatever contact type")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With