Hi,all!
I want to submit  ''address'' value in the location model .
And I want to submit ''address'' value in the
room/_form.html.erb .
So,I am using nested_form but it doesn''t work. Please teach me some
advice.
Error message is like this.
[code]
ActiveRecord::AssociationTypeMismatch (Location(#70291171806880) expected,
got ActiveSupport::HashWithIndifferentAccess(#70291193905860)):
  app/controllers/rooms_controller.rb:44:in `create''
[/code]
My db/schema is following...
[code]
...
  create_table "locations", :force => true do |t|
    t.string   "address"
    t.float    "latitude"
    t.float    "longitude"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  create_table "rooms", :force => true do |t|
    t.string   "room_name"
    t.text     "description"
    t.string   "pref_name"
    t.string   "email"
    t.integer  "user_id"
    t.integer  "price"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
...
[/code]
Room model is ...
[code]
class Room < ActiveRecord::Base
  belongs_to :location
  belongs_to :user
  accepts_nested_attributes_for :location,:allow_destroy => true
...
[/code]
#rooms/_form.html.erb
[code]
<div>
    <%= f.fields_for @location do |loc| %>
      <%= loc.label "address" %><br/>
      <%= loc.text_field :address %>
    <% end %>
  </div>
[/code]
# rooms_controller.rb
[code]
  def new
    @room = current_user.rooms.build
    @location = current_user.locations.build
    respond_to do |format|
      format.html # new.html.erb
    end
  end
....
  def create
    @room = current_user.rooms.build(params[:room])
    @location = current_user.locations.build(params[:location])
    respond_to do |format|
      if @room.save
        format.html { redirect_to(@room, :notice => ''Room was
successfully
created.'') }
      else
         format.html { render :action => "new" }
      end
    end
  end
[/code]
Thanks!
-- 
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.