我有这个模型(Rails 4.2.7):
class User < ActiveRecord::Base
accepts_nested_attributes_for :pseudonyms, reject_if: proc { |attributes| attributes['name'].blank? }, allow_destroy: true
has_many: pseudonyms
end
class Pseudonym < ActiveRecord::Base
belongs_to :user
validates :name, :presence => true
validates :www, :presence => true
end
查看用户/编辑:
<%= form_for(@user) do |f| %>
<%= f.fields_for :pseudonyms do |ff| %>
<%= f.form_group :name do |f| %>
<%= f.text_field :name, class: 'form-control col-xs-12 ' %>
<%= f.text_field :www, class: 'form-control col-xs-12 ' %>
<% end %>
<% end %>
<%= link_to_add_association _("add another"), f, :pseudonyms, :class => "btn btn-sm btn-primary pull-right" %>
<% end %>
当我用空名或www保存时,我收到消息:
Www不能为空。
我已尝试过所有这些组合(en.yml):
en:
activerecord:
models:
user:
pseudonyms.name: "Pseudonym"
pseudonyms.www: "Website"
pseudonym.name: "Pseudonym"
pseudonym.www: "Website"
pseudonyms:
name: "Pseudonym"
www: "Website"
pseudonym:
name: "Pseudonym"
www: "Website"
pseudonym:
name: "Pseudonym"
www: "Website"
user/pseudonyms:
name: "Pseudonym"
www: "Website"
user/pseudonym:
name: "Pseudonym"
www: "Website"
attributes:
user/pseudonyms:
name: "Pseudonym"
www: "Website"
user/pseudonym:
name: "Pseudonym"
www: "Website"
user:
pseudonyms.name: "Pseudonym"
pseudonyms.www: "Website"
pseudonym.name: "Pseudonym"
pseudonym.www: "Website"
pseudonyms:
name: "Pseudonym"
www: "Website"
pseudonym:
name: "Pseudonym"
www: "Website"
没有任何结果。有什么不对吗?
我更愿意使用gem gettext进行翻译,但这不是必需的。
谢谢, 大卫