You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
Per the documentation, to check if a user has the ability to do something to any element in the view, you do something like this:
<% if can? :create, @project %><%= link_to "New Project", new_project_path %><% end %>
Or you can check with the class like:
<% if can? :create, Project %><%= link_to "New Project", new_project_path %><% end %>
In my case, I have a DashboardController#Index, that has this:
@nodes=current_user.nodes.where(:is_comment=>nil)
In my views/dashboard/index.html.erb, I have this:
<% @nodes.each do |node| %><!-- Upload Video Comment Popup --><divclass="box"><%=renderpartial: "shared/comments",locals: {node: node}%></div><%end%><!-- node -->
Then in my shared/_comments.html.erb, I have this:
<% if node.comments.present? %><% node.comments.each do |comment| %><% if can? :manage, Comment %>
Show Something Interesting Here
<% else %>
Show something boring here
<% end %><% end %><% end %>
That doesn't work.
I also tried this:
<% if node.comments.present? %><% node.comments.each do |comment| %><% if can? :manage, comment %>
Show Something Interesting Here
<% else %>
Show something boring here
<% end %><% end %><% end %>
And that doesn't work either.
This is my ability.rb
can:manage,Comment,user_id: user.id
I thought about creating a @comments instance variable in the controller, but the issue with that is that the comments are on a collection of nodes (i.e. I need to show multiple nodes, and each node has multiple comments).
How do I approach this?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Per the documentation, to check if a user has the ability to do something to any element in the view, you do something like this:
Or you can check with the class like:
In my case, I have a
DashboardController#Index
, that has this:In my
views/dashboard/index.html.erb
, I have this:Then in my
shared/_comments.html.erb
, I have this:That doesn't work.
I also tried this:
And that doesn't work either.
This is my
ability.rb
I thought about creating a
@comments
instance variable in the controller, but the issue with that is that thecomments
are on a collection of nodes (i.e. I need to show multiple nodes, and each node has multiple comments).How do I approach this?
The text was updated successfully, but these errors were encountered: