0
votes

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

1 Answers

1
votes

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|