ruby on rails - two different actions on same button -


i developing 1 simple demo application room reservation have 3 tables member_types, customers, , donors

the models follows

class membertype < activerecord::base  has_one  :donor  has_many :customers  has_many :room_rates  attr_accessible :member_type end  class customer < activerecord::base   belongs_to :member_type    has_one  :donor   has_many :rooms   has_many :room_types   has_many :room_rates end  class donor < activerecord::base   belongs_to :customer   belongs_to :member_type    attr_accessible :donation, :free_days, :used_days,:customer_id end 

i have added member_types donor, guest , 2 other admin when customers add basic info select member_type donor , submitting stores info in customer table

how can add customer_id in donor table when customer submit info?

you can use active record callback in customer model, this:

class customer< activerecord::base   after_save :new_donor    private    def new_donor     new_record = donor.new(:customer_id => self.id)     new_record.save   end  end 

btw, have closed loop relation in model design (room_rates belongs member_type , customer) not best practice in table design although it's not totally wrong either.
if possible, may want redesign it


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -