ruby on rails - How do I check CanCan abilities on an object in a `shared/partial`? -


per CanCan documentation, to check that a user can do something for any element In this scenario, you do something like this:

  & lt;% if it can be? : Create, @ project% & gt; & Lt;% = link_to "new project", new_project_path%> & Lt;% end% & gt;  

Or you can check with this type of class:

  & lt;% if it can be? : Creating, Project% & gt; & Lt;% = link_to "new project", new_project_path%> & Lt;% end% & gt;  

In my case, I have a Dashboard Controller # Index , which has this:

  @nodes = current_user .nodes in my  view / dashboard / index.html.erb  I have this: 

  

  and lt;% @ Nodes.each do | Node | & Gt%; & Lt ;! - Upload video comment popup - & gt; & Lt; Div class = "box" & gt; & Lt;% = Partial render: "shared / comments", local: {node: node}%> & Lt; / Div & gt; & Lt;% end% & gt; & Lt ;! - node - & gt;  

Then in my shared / _comments.html.erb , I have this:

  <% if the node Comtems .present? & Gt%; & Lt;% node.comments.each do | Comment | & Gt%; & Lt;% If so? : Management, Comment% & gt; Show something interesting here & lt;% else% & gt; Show some boring here & lt;% end% & gt; & Lt;% end% & gt; & Lt;% end% & gt;  

This does not work.

I also tried:

   

And that does not work too.

This is my capacity. RB

  can: Regarding creating a  @comments  example variable in the controller, I thought management, comment, user_id: user.id  

, but the problem with it is that the comments are on the collection of nodes (i need to show several nodes, and there are many comments in each node) .

How do I give it?

After updating CanCanCommunity version of Cancun, your last code should work

  & lt;% if node comments.present? & Gt%; & Lt;% node.comments.each do | Comment | & Gt%; & Lt;% If so? : Management, Comment% & gt; Show something interesting here & lt;% else% & gt; Show some boring here & lt;% end% & gt; & Lt;% end% & gt; & Lt;% end% & gt; Related to  


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -