Ruby on Rails Sunday, January 29, 2012

HI All,

I am having Model "Customer" using STI for sender and receiver, and i am unable to save the both sender and receiver by nested attribute. Below are my model and active admin resource codes, correct me if i am wrong nested attribute on concept.

CUSTOMER MODEL:

class Customer < ActiveRecord::Base
belongs_to
:sender, :class_name => "Customer"
has_many
:receivers, :class_name => "Customer", :foreign_key => 'sender_id'
has_many
:packages

accepts_nested_attributes_for
:packages
accepts_nested_attributes_for
:receivers
end

CUSTOMER ADMIN INTERFACE
:

ActiveAdmin.register Customer do
form
do |f|
 f
.inputs "Sender Details" do
     f
.input :name
 f
.input :email
 f
.input :street
 f
.input :city
 f
.input :state
 f
.input :pin
 
end

  f
.inputs  do
f
.has_many :receivers do |p|
 f
.input :name
 f
.input :email
 f
.input :street
 f
.input :city
 f
.input :state
 f
.input :pin
 
end
end
f
.inputs do #packages are saving correctly
 f
.has_many :packages do |p|
  p
.input :weight
  p
.input :amount
  p
.input :received_date
  p
.input :amount
end
 
end
  f
.buttons
 
end
end


regards,
Loganathan




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment