I have the following code in my games_controller edit section:
def edit
@game = Game.find_by_game_name(params[:id])
respond_to do |format|
if current_user.id == @game.user_id
format.html
else
format.html { redirect_to games_path, notice: 'You are not authorized to change these details.'}
end
end
end
My problem is that if I click on the edit feature even for those games who do belong to a user I goes to the else line with the notice saying I am not authorized to change these details. The user_id field of the games matches with the id of the user but it won’t let me edit. Any ideas why this might be?
You have pretty much asked the same thing as can be seen in this :
if current_user.id = @game.user_id
It will work if you do it this way.
In your current example, it probably does not work because you are not properly authorized. Try removing the if and see if it works at all without it.