Question

I got two models in my app: Post and Review, nested in Post. They both has belong_to relation with User model used by Devise gem. All relations seem to be correct there. The problem is that when I want to get Post author, I can do it as I wrote this in my Post controller(create method):

@post.user_id = current_user.id

But I did it fpr reviews as well:

def create
@post = Post.find(params[:postl_id])
@review = @post.reviews.create(review_params)
@review.user_id = current_user.id
redirect_to post_path(@post)
end

Still I do not see any data in user_id column in Reviews table when I create review.

Show me please where am I wrong.

Was it helpful?

Solution

@review = @post.reviews.create(review_params.merge({:user_id => current_user.id}))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top