unknown attribute 'valoracion_id' for Rating

0

I get that error in the controller

def create
val=Valoracion.all
    val.each do |app|
      Rating.create(:user_id => params[:rating][:user_id],
                    :app_id=> params[:rating][:app_id],
                    :valoracion_id => app.id,
                    :valoracion => params[:rating][:valoracion][app.id]
                    )                                                  
     end   
 end    

rating.rb

class Rating < ApplicationRecord
  belongs_to :app
  belongs_to :user
  belongs_to :valoracion
end

valoracion.rb

class Valoracion < ApplicationRecord
  has_many :ratings
 end
    
asked by Brayan Jimenez 10.04.2017 в 22:33
source

1 answer

1

Your table ratings has no column named valoracion_id . You must add it in the database. Try running in the terminal

rails generate migration add_valoracion_to_ratings valoracion:references

This will generate a migration file that will add the column you need. To make it effective, execute:

rake db:migrate db:test:prepare

    
answered by 11.04.2017 в 22:10