I have a rail app setup with devise and i am now adding cancan. The problem i am having is that where ever i have can? in my views, it adds a number. It only does this if the user does have the permission for the action. Everything else is working perfectly, it''s just these annoying numbers! The club model and controller are just default as the scaffold generated, except i have a habtm with roles. @clubs.each do |club| %tr %td= club.name %td= link_to ''Show'', club = if can? :update, club %td= link_to ''Edit'', edit_club_path(club) = if can? :destroy, club %td= link_to ''Destroy'', club, :confirm => ''Are you sure?'', :method => :delete Would generate the following if the user is an admin <tr> <td>football</td> <td><a href="/clubs/11">Show</a></td> <td><a href="/clubs/11/edit">Edit</a></td> 2 <td><a href="/clubs/11" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a></td> 2 </tr> But would generate the following if they are a guest <tr> <td>football</td> <td><a href="/clubs/11">Show</a></td> </tr> Why is cancan leaving 2''s in my views? Has anyone else had this problem? Where would i even begin to troubleshoot this? ruby 1.9.3 rails 3.2.2 cancan 1.6.7 devise 2.0.4 Thank you, scott -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/j0Dn9bOgXQAJ. 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.
> = if can? :update, club > %td= link_to ''Edit'', edit_club_path(club)You should be using - if can? :update, club Using = tells haml that you want the result of the if expression (ie the value that "can? :update, club") to be output in the view. Fred -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Yo should write as this: @clubs.each do |club| %tr %td= club.name %td= link_to ''Show'', club - if can? :update, club %td= link_to ''Edit'', edit_club_path(club) - if can? :destroy, club %td= link_to ''Destroy'', club, :confirm => ''Are you sure?'', :method => :delete using ''-'' instead of ''='' in sentences with no html output byeeee El jue, 22-03-2012 a las 16:30 -0700, scott escribió:> I have a rail app setup with devise and i am now adding cancan. > > > The problem i am having is that where ever i have can? in my views, it > adds a number. It only does this if the user does have the permission > for the action. Everything else is working perfectly, it''s just these > annoying numbers! > > > The club model and controller are just default as the scaffold > generated, except i have a habtm with roles. > > > @clubs.each do |club| > %tr > %td= club.name > %td= link_to ''Show'', club > = if can? :update, club > %td= link_to ''Edit'', edit_club_path(club) > = if can? :destroy, club > %td= link_to ''Destroy'', club, :confirm => ''Are you > sure?'', :method => :delete > > > Would generate the following if the user is an admin > > > <tr> > <td>football</td> > <td><a href="/clubs/11">Show</a></td> > <td><a href="/clubs/11/edit">Edit</a></td> > 2 > <td><a href="/clubs/11" data-confirm="Are you sure?" > data-method="delete" rel="nofollow">Destroy</a></td> > 2 > </tr> > > > But would generate the following if they are a guest > > > <tr> > <td>football</td> > <td><a href="/clubs/11">Show</a></td> > > > > > </tr> > > > > > Why is cancan leaving 2''s in my views? > Has anyone else had this problem? > Where would i even begin to troubleshoot this? > > > ruby 1.9.3 > rails 3.2.2 > cancan 1.6.7 > devise 2.0.4 > > > Thank you, > scott > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/j0Dn9bOgXQAJ. > 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.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Friday, March 23, 2012 5:50:09 AM UTC-4, Frederick Cheung wrote:> > > > > = if can? :update, club > > %td= link_to ''Edit'', edit_club_path(club) > > You should be using > > - if can? :update, club > > Using = tells haml that you want the result of the if expression (ie > the value that "can? :update, club") to be output in the view. > > Fred >that fixed it. i love when my mistakes are so easy to fix. thank you, scott -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/LDSN1rIv02YJ. 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.