I\'m new to Rails. I\'m building my first app - simple blog. I have User and Post models, where each user can write many posts. Now I want to add Comment model, where each post
In your way you should put this:
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create(comment_params)
@comment.user_id = current_user.id #or whatever is you session name
if @comment.save
redirect_to @post
else
flash.now[:danger] = "error"
end
end
And also you should remove user_id from comment_params as strong parameters . Hope this will help you .