如何在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