i18n for select boxes

前端 未结 1 670
甜味超标
甜味超标 2021-01-05 02:17

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.col         


        
相关标签:
1条回答
  • 2021-01-05 02:47

    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 -%>
    
    0 讨论(0)
提交回复
热议问题