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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The comparison should be using ==. If you use a single = you''re assigning the variable, which would always return true. On Fri, Mar 2, 2012 at 3:18 PM, Christopher Jones <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> 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? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ~ Jeremiah:9:23-24 Android 2D MMORPG: http://solrpg.com/, http://www.youtube.com/user/revoltingx -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 2, 2012, at 4:18 PM, Christopher Jones wrote:> 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 %>---- not entirely sure of your ''current_user.id'' usage nor the match potential to @game.user_id but when you want to test a value (=) you actually have to use 2 of them... == thus syntax s/b ''if current_user.id == @game.user_id'' Craig -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 03/02/2012 04:18 PM, Christopher Jones wrote:> 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?Where does current_user come from. It probably should be an instance variable @current_user -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.