如何在Rails中本地化嵌套虚拟属性?本地化Rails中的嵌套虚拟属性
模型:
class User < ActiveRecord::Base
attr_accessor :company_information # This is used in callbacks etc
end
和视图:
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: {class: 'form-horizontal'}) do |f|
= devise_error_messages!
= f.input :email
= f.input :password
= f.input :password_confirmation
= f.simple_fields_for :company_information do |c|
= c.input :name # This is what I want to localise
= f.button :submit
翻译键(从en.yml
)等activerecord.attributes.user.company_information.name
和activerecord.attributes.user.company_information_name
不拾取。
我试过这个解决方案,虽然看起来完美的形式,如果有一个验证错误,那么这不会被拿起,它会恢复到默认值。 有什么建议吗? – richard 2013-09-19 02:28:33