0

I have a model Event and a model Serie. They are defined like this:

in event.rb

belongs_to :serie
accepts_nested_attributes_for :serie
attr_accessible :serie

in serie.rb

has_many :events

Event table has the serie_id key.

In the event form I have pretty much the following:

 form_for @event do |f|
   ...
   ...
   f.fields_for @event.serie do |serie_f|
     ....
   end
 end

The request to the controller is coming like this:

... "event"=>{...., "serie"=>{"..."=>"19/12/2012", ....}, ...}...

In the create action of events_controller I have:

def create
  @event = current_user.events.new(params[:event])
  ....

In this line I get the following error:

ActiveRecord::AssociationTypeMismatch (Serie(#134112340) expected, got ActiveSupport::HashWithIndifferentAccess(#92663620))

Unsure what the problem is

1 Answer 1

1

You should check this question : ActiveRecord::AssociationTypeMismatch when attempting to save nested attributes in Rails.
I think that you simply have to replace attr_accessible :serie by attr_accessible :serie_attributes in your model.
And in your view, try f.fields_for :serie do |serie_f| instead of f.fields_for @event.serie do |serie_f|

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.