Created
February 9, 2009 22:21
-
-
Save bclennox/61064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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