Локализовать вложенный виртуальный атрибут в Rails - PullRequest
3 голосов
/ 13 февраля 2012

Как можно локализовать вложенный виртуальный атрибут в 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, не подобраны.

Ответы [ 2 ]

1 голос
/ 07 ноября 2013

Кажется, вы используете gem simple_form для генерации форм.Вот что сработало для меня.

en:
  simple_form:
    labels:
      user:
        company_information:
          name: My Name

Ссылка на главу простой формы также может быть полезна.

0 голосов
/ 02 марта 2012

В рельсах 3 я нашел один путь.В вашем случае перевод будет helpers.label.user[company_information].name в en.yml, он будет выглядеть так:

en:
  helpers:
    label:
      "user[company_information]":
        name:"Name"
...