设置模型嵌入在合作伙伴模型中。转换合作伙伴模型属性,但不设置模型属性。我试过了
en:
mongoid:
attributes:
partner:
name: "Name"
company_name: "Company"
setting:
prefix: "Prefix!"
suffix: "Suffix!"
和
en:
mongoid:
attributes:
partner:
name: "Name"
company_name: "Company"
setting:
prefix: "Prefix!"
suffix: "Suffix!"
两者都不起作用。
如何翻译设置模型属性?
感谢panmari。 那些在视图文件中使用。我想要“s.label:prefix”show“Prefix!”在结果中。
= form_for @partner do |f|
table.table
tr
td
= f.label :name
= f.text_field :name, :class => "form-control"
td
= f.label :company_name
= f.text_field :company_name, :class => "form-control"
= f.fields_for :setting do |s|
tr
td
= s.label :prefix
= s.text_field :prefix, :class => "form-control"
td
= s.label :suffix
= s.text_field :suffix, :class => "form-control"
.card-footer
= button_tag :type => "submit", :class => 'btn btn-primary-outline btn-block' do
i.fa.fa-check-circle.fa-lg
| Submit
现在我在下面尝试过,它也不起作用
en:
mongoid:
attributes:
partner:
name: "Name"
company_name: "Company"
settings:
prefix: "Prefix!"
suffix: "Suffix!"
我在语言环境文件中恢复了“设置”,并自定义了错误视图。然后我收到了这个错误。所以它仍然不起作用,但复数“设置”似乎是正确的。
I18n::InvalidPluralizationData in PartnersController#create
translation data {:prefix=>"Prefix!", :suffix=>"Suffix!"} can not be used with :count => 1
以下是错误视图,以防万一。
- if @partner.errors.any?
- if @partner.errors.messages[:setting]
- @partner.errors.messages.delete(:setting)
.alert.alert-danger style="text-align:center"
button.close type="button" data-dismiss="alert" aria-label="Close"
span aria-hidden="true"
i.fa.fa-times.fa-lg.text-danger
span.sr-only
|Close
div style="display:inline-block;text-align:left;"
i.fa.fa-exclamation-circle.fa-lg
- if @partner.setting.errors.any?
| #{@partner.errors.count+@partner.setting.errors.count}
- else
| #{@partner.errors.count}
ul
- @partner.errors.full_messages.each do |message|
li style="min-width:10rem;" = message
- if @partner.setting.errors.any?
- @partner.setting.errors.full_messages.each do |message|
li style="min-width:10rem;" = message