I have an action create in Comments controller like this
def create
@comment = Comment.new(comment_params)
@comment.user = current_user
@comment.post = @post
if @comment.save
flash[:notice] = 'Comment was successfully created!'
redirect_to root_path
else
flash[:alert] = "Cant add comment.\n#{@comment.errors.full_messages.join(',')}"
redirect_to root_path
end
end
The request to this action goes from form on index page. Now I want to use the same form on show page. Question: how make condition like this:
if @comment.save
if something
redirect_to show_path
else
redirect_to root_path
end
else
if something
redirect_to show_path
else
redirect_to root_path
end
end