Skip to content

Instantly share code, notes, and snippets.

@bclennox
Created February 9, 2009 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bclennox/61064 to your computer and use it in GitHub Desktop.
Save bclennox/61064 to your computer and use it in GitHub Desktop.
# app/models/address.rb
class Address < ActiveRecord::Base
end
# app/models/event.rb
class Event < ActiveRecord::Base
belongs_to :address
end
# app/models/contact.rb
class Contact < ActiveRecord::Base
belongs_to :address
end
# app/views/events/edit.html.haml
- form_for :event do |f|
%p= f.text_field :name
- f.fields_for :address do |a|
%p= a.text_field :street
# ...
# app/controllers/events_controller.rb
def update
@event = Event.find(params[:id])
@event.update_attributes(params[:event])
if @event.save
render :text => 'You got it.'
else
render :text => 'You lost it.'
end
end
# error and parameters
ActiveRecord::AssociationTypeMismatch in EventsController#update
Address(#31131890) expected, got HashWithIndifferentAccess(#9690560)
{"commit"=>"Update",
"_method"=>"put",
"authenticity_token"=>"deb51c9504aa6b2090238780498fea660fa4d079",
"id"=>"1",
"event"=>{"name"=>"SuperEvent",
"address"=>{"city"=>"Raleigh",
"postal_code"=>"27239",
"country"=>"USA",
"street"=>"123 Streety St.",
"state"=>"NC"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment