ship.rb 800 字节
Newer Older
1 2
class Ship < ActiveRecord::Base
  self.record_timestamps = false
3

4
  belongs_to :pirate
5
  belongs_to :update_only_pirate, :class_name => 'Pirate'
6
  has_many :parts, :class_name => 'ShipPart'
7

8
  accepts_nested_attributes_for :parts, :allow_destroy => true
9
  accepts_nested_attributes_for :pirate, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
10
  accepts_nested_attributes_for :update_only_pirate, :update_only => true
11 12

  validates_presence_of :name
13 14 15 16 17 18

  attr_accessor :cancel_save_from_callback
  before_save :cancel_save_callback_method, :if => :cancel_save_from_callback
  def cancel_save_callback_method
    false
  end
19
end
20 21 22 23 24 25

class FamousShip < ActiveRecord::Base
  self.table_name = 'ships'
  belongs_to :famous_pirate
  validates_presence_of :name, on: :conference
end