rails中collection_select的标签选项

时间:2017-11-22 07:28:59

标签: ruby-on-rails haml rails-i18n

我已经为选择框标签应用了本地化,如下所示。标签选项不在rails_select中以rails形式工作。如何更改代码以获取标签

更新

 = simple_form_for @product do |f|
  = error_notification f
  .form-inputs
    .row
      .span5
        = f.input :name, :input_html => {:maxlength => 100}
      .span5
        - unless @product.company.nil?
          = f.input :company_id, :as => :hidden, :input_html => { :value => @product.company.id}
        - else
          = f.association :company, :prompt => "Select Company"
    .row
      .span10
        %div#product_existence_message
        - unless @product.company.nil?
          = f.collection_select :product_type_id, ProductType.all,:id, :name, {:prompt => 'Select Product Type', :label => :label => t('forms.products.label.name'), :selected =>@product.product_type_id } 

1 个答案:

答案 0 :(得分:0)

文件:en.yml

en:
  activerecord:
    attributes:
      product:
        product_type: 'Product Type translation here'

文件:template.html.erb

<%= label(:product, product_type) %>
# => <label for="product_product_type">Product Type translation here</label>

参考:https://apidock.com/rails/ActionView/Helpers/FormHelper/label[https://apidock.com/rails/ActionView/Helpers/FormHelper/label]