问题
I have a question regarding the simple_form gem
.
If I have two languages and use the t('')
function from to translate text, which I have put into my .yml
files.
When using <%= f.association :type %>
, is it possible to let simple_form render
<select value="database_value1">t('database_value1')</select>
?
Thank you
回答1:
Possibly, it'll translate collections for you: https://github.com/plataformatec/simple_form
Association docs: http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder:association
From the docs
Simple Form also has support for translating options in collection helpers. For instance, given a User with a :gender attribute, you might want to create a select box showing translated labels that would post either male or female as value. With Simple Form you could create an input like this:
f.input :gender, collection: [:male, :female]
And Simple Form will try a lookup like this in your locale file, to find the right labels to show:
en:
simple_form:
options:
user:
gender:
male: 'Male'
female: 'Female'
Maybe try: <%= f.association :type, collection: [:some, :collection, :options]%>
来源:https://stackoverflow.com/questions/22581490/rails-simple-form-association-with-i18n