if current_user.id = game.user_id

Hi all,

I have links to the show pages for each game in my project and if the games user_id matches the id of the currently signed in user then I want it to display the edit button if they are not then it shouldn't display.

I currently have the following code set but it doesn't work. Every game has the edit button display. The code is as followed:

<% if current_user.id = @game.user_id %> <div id="text3"><%= link_to 'Edit', edit_game_path(@game) %></div><br /> <% end %>

Any ideas?

The comparison should be using ==.

If you use a single = you’re assigning the variable, which would always return true.

Hi all,

I have links to the show pages for each game in my project and if the games user_id matches the id of the currently signed in user then I want it to display the edit button if they are not then it shouldn't display.

I currently have the following code set but it doesn't work. Every game has the edit button display. The code is as followed:

<% if current_user.id = @game.user_id %> <div id="text3"><%= link_to 'Edit', edit_game_path(@game) %></div><br /> <% end %>

Where does current_user come from. It probably should be an instance variable @current_user