Nested attributes not saving but IDs do

sanvp

New Member
I have been attempting to get a new record to save based on two models with a go through relationship on one form. As of now the code creates the records in the tables with the proper IDs but no values are saved in the tables from the form input. The models are as follows:\[code\] class Account < ActiveRecord::Base attr_accessible :alt_email, :c_address_id, :company, :do_not_call, :email, :first_name, :last_name, :mobile, :phone, :salutation, :subscribe, :title belongs_to :user validates :user_id, presence: true has_many :account_addresses has_many :addresses, through: :account_addresses #accepts_nested_attributes_for :addresses, allow_destroy: false attr_accessor :house, :street, :street2, :city, :state, :zipcode end class AccountAddress < ActiveRecord::Base attr_accessible :account_id, :address_id, :deleted belongs_to :account belongs_to :address end class Address < ActiveRecord::Base attr_accessible :city, :country, :full_address, :geo_verified, :house, :latitude, :longitude, :state, :street, :street2, :zipcode has_many :account_addresses has_many :accounts, through: :account_addresses def self.create_from_user(opts) a = Address.new a.house = opts[:house] a.street = opts[:street] a.street2 = opts[:street2] a.city = opts[:city] a.state = opts[:state] a.zipcode = opts[:zipcode] a.country = opts[:country] a.save return a end end\[/code\]The controller code for create is as follows:\[code\] def create success = false @account = current_user.accounts.new account_saved = @account.save @address = Address.create_from_user({house: @account.house, street: @account.street, street2: @account.street2, city: @account.city, state: @account.state, zipcode: @account.zipcode}) address_saved = @address.errors.none? if account_saved && address_saved account_address = AccountAddress.new account_address.account_id = @account.id account_address.address_id = @address.id account_address.save success = true else success = false end respond_to do |format| if success format.html { redirect_to @account, notice: 'Customer was successfully created.' } format.json { render json: @account, status: :created, location: @account } else format.html { render action: "new" } format.json { render json: @account.errors, status: :unprocessable_entity } end end end\[/code\]I looked at doing this with accepts_nested_attributes_for but did not see how that would work for the relationships. Open to suggestions outside of this. Looking at the tail log it is processing the insertions as noted by the creation of the records but the values showVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)Nothing special with the formThanks in advance for your assistance.
 
Top