Thursday, June 11, 2009

June 11th Relations between tables Draft

I created a draft for the donor account system.

donor has_one address, phone_number, email, account
and
donor has_many donations

To accomplish these connection between tables,
I use " accepts_nested_attributes_for ".

For example,

in donor.rb
has_one :address
accepts_nested_attributes_for :address

in donor controller
add these to new and edit functions:
@donor.build_address unless @donor.address

in view:
<% f.fields_for :address do |a| %>
... ...
<% end %>

------
Preview:



login GUI:

No comments:

Post a Comment