0

I am getting the following error in my tests in this Ruby project I am doing. I can't seem to figure out why. Below is my controller.

class ReviewsController < ApplicationController

def new
@restaurant = Restaurant.find(params[:restaurant_id])
@review = Review.new
end

def create
@restaurant = Restaurant.find(params[:restaurant_id])
@restaurant.reviews.create(review_params)
end
private
 def review_params
 params.require(:review).permit(:thoughts, :rating)
 end

end

Below is my view for the Reviews.

<%= form_for [@restaurant, @review] do |f| %>
<%= f.label :thoughts %>
<%= f.text_area :thoughts %>
<%= f.label :rating %>
<%= f.select :rating, (1..5) %>
<%= f.submit 'Leave Review' %>
 <% end %>

I can't seem to figure out what is wrong.

1 Answer 1

1

The model for the Review is wrong. My model was referring to the wrong class.

class Restaurant < ApplicationRecord
belongs_to :restaurant
end

When it should have been the following.

class Review < ApplicationRecord
belongs_to :restaurant
end

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.