Problem with Association on rails 3

advertisements

View

<%= form_for @product, :url => admin_products_path do |f| %>
<div>
  <%= f.label :name %>
  <%= f.text_field :name %>
</div>

<div>
  <%= f.label :description %>
  <%= f.text_area :description, :rows => 7 %>
</div>
<%= f.fields_for :address do |a| %>
  <p><%= a.label "Address One" %><br />
    <%= a.text_field :address_one %></p>

  <p><%= a.label "Address Two" %><br />
    <%= a.text_field :address_two %></p>

  <p><%= a.label :city %><br />
    <%= a.text_field :city %></p>

  <p><%= a.label :postcode %><br />
    <%= a.text_field :postcode %></p>

    <p><%= a.label :country %><br />
    <%= a.select :country_id, Country.active.collect {|p| [ p.printable_name, p.id ] } %></p>
<% end %>
<% end %>

Controller

 def create
   @product = Product.new(params[:product])
    if @product.save
      flash[:notice] = 'Product was successfully created.'
      render 'show'
    else
      render 'new'
    end
  end

model

class Product < ActiveRecord::Base
  has_one :address, :as => :addressable
end

but when save data it show issue:
Address(#93165130) expected,got ActiveSupport::HashWithIndifferentAccess(#79365750)

Please help me solved this problem


Try if adding accepts_nested_attributes_for :address solves this.