Skip to content

Instantly share code, notes, and snippets.

@juandazapata
Last active December 16, 2015 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juandazapata/5406887 to your computer and use it in GitHub Desktop.
Save juandazapata/5406887 to your computer and use it in GitHub Desktop.
Localized model
class Hostel < ActiveRecord::Base
  attr_accessible :name, :address_1...
  
  # Model definition...
  has_one :conditions, class_name: 'Hostel::Condition'
  has_one :directions, class_name: 'Hostel::Direction'
end

class Hostel::Condition < ActiveRecord::Base
  attr_accessible :hostel_id, :es, :pt, :en
  
  # Model definition...
  belongs_to :hostel
end

class Hostel::Direction < ActiveRecord::Base
  attr_accessible :hostel_id, :es, :pt, :en
  
  # Model definition...
  belongs_to :hostel
end

To query a localized field:

conditions = Hostel.find(999).condition.es
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment