I have a model named Role. And i am using the helper below in a form. Is there a way to change the value of name attribute to another language?
<%= f.collection_select :role_id, Role.all, :id, name, {} -%>
locales/de.yml
de:
role:
admin: "something"
editor: "something something"
In the model:
class Role < ActiveRecord::Base
def translated_name
I18n.t(name, :scope => 'role')
end
end
In the view:
<%= f.collection_select :role_id, Role.all, :id, :translated_name -%>
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