error when creating record ActiveRecord :: AssociationTypeMismatch in RatingsController # create

0

When trying to insert a record I get an error in the controller

  

Rating (# 47310743451000) expected, got String (# 47310719254620)

This is the instruction:

sql=  Rating.create(:user_id => params[:rating][:user_id],
                    :app_id=> params[:rating][:app_id],
                    :valoracion_id => app.id,
                    :valoracion => params[:rating][:valoracion][nombre])
end
    
asked by Brayan Jimenez 24.04.2017 в 22:31
source

1 answer

1

The problem is here

:valoracion => params[:rating][:valoracion][nombre]

When you make a create and pass a key with the name of the relation: valuation, you are expected to pass it a Valuation object and not a string.

It should be this way or similar:

Rating.create(:user_id => params[:rating][:user_id],
                    :app_id=> params[:rating][:app_id],
                    :valoracion_id => app.id,
                    :valoracion => Valoracion.find_by_nombre(params[:rating][:valoracion][nombre]))

Similarly confuses me that you assign at the same time: valuation and: valoración_id in the same create. I would like to see the Rating class to see their associations.

    
answered by 25.04.2017 в 06:00