public
Last active

I18n nested attributes

  • Download Gist
ar.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class Address < ActiveRecord::Base
belongs_to :addressable, polymorphic: true
validates_presence_of :name, :street, :city, :zip, :country
end
 
class User < ActiveRecord::Base
has_one :address, as: :addressable
validates_presence_of :login
accepts_nested_attributes_for :address
end
 
class Company < ActiveRecord::Base
has_many :addresses, as: :addressable
validates_presence_of :name
accepts_nested_attributes_for :addresses
end
de.yml
YAML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
de:
activerecord:
attributes:
address:
name: Name
street: Straße
city: Stadt
zip: PLZ
country: Land
user:
login: Benutzername
address/name: Name
address/street: Straße
address/city: Stadt
address/zip: PLZ
address/country: Land
company:
name: Name
addresses/name: Anschrift # this one differs
addresses/street: Straße
addresses/city: Stadt
addresses/zip: PLZ
addresses/country: Land
 
# some time ago, this had worked, too:
# address: &address_attributes
# name: ...
# ...
# user:
# login: Benutzername
# address:
# <<: *address_attributes
# company:
# name: Name
# addresses:
# <<: *address_attributes
# name: Anschrift

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.