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 myview / dashboard / index.html.erbI 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. RBcan: Regarding creating a@commentsexample variable in the controller, I thought management, comment, user_id: user.id, but the problem with it is that the
commentsare 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
Post a Comment