Skip to content

Instantly share code, notes, and snippets.

@Fire-Dragon-DoL
Created February 17, 2013 17:10
Show Gist options
  • Save Fire-Dragon-DoL/4972326 to your computer and use it in GitHub Desktop.
Save Fire-Dragon-DoL/4972326 to your computer and use it in GitHub Desktop.
class TechSpec < ActiveRecord::Base
validates :boat_id, presence: true
validates :tech_spec_name_id, presence: true, uniqueness: { scope: :boat_id }
belongs_to :boat
belongs_to :tech_spec_name
acts_as_list scope: :boat
def as_json(options = {})
super(options.merge(methods: [self.name]))
end
def name
self.tech_spec_name.name
end
def name=(value)
tmp_tech_spec_name = TechSpecName.find_or_create(name: value)
tmp_tech_spec_name.save
self.tech_spec_name = tmp_tech_spec_name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment