Comments (3)
Hi,
I think you need to use:
if can?(:update, comment)
You need to pass the comment instance to check the ability
And if you want to raise and exception inserting the corresponding URL you need to set a before filter in the corresponding Controller. See the Authorizing Controller Actions section in the readme of CanCan
from cancan.
well, thank you i've forgotten authorizing the correspondent controller, besides, the comment model that i'm working with, belongs polymorphicly to a Request model, i think because that the :nested atribute of load_and_authorize_resource method
in that way i've solved that problem, but i still don't see the links like
- if can? :update, Comment
= link_to t('edit'), edit_request_comment_path(comment.commentable, comment)
and my ability.rb model is something like this
class Ability include CanCan::Ability def initialize(user) can [:read, :create, :update, :destroy], Comment do |comment| comment.try(:user) == user end if user.role == "admin" can :manage, :all elsif user.role == "qa" can [:read, :accept], Request elsif user.role == "client" can :read, Request can [:update, :destroy, :create, :suspend, :resume], Request do |request| request.try(:user) == user end end end end
why i can't see those links?
the use of brackets doesn't affect this behavior, greetings
from cancan.
i've solved this, really i wasn't read well what means you anwer @pacoguzman, you've right this was about that i was passing the Comment class, not de comment instance object to check the abilities, thank you
from cancan.
Related Issues (20)
- User Interface HOT 2
- initialize method not called in production mode HOT 1
- show and edit are unauthorized on authorized (:manage) object HOT 1
- Called user model an alternative name
- PROJECT DISCONTINUED. STOP CREATING ISSUES AND GOTO CANCANCAN INSTEAD HOT 5
- lear
- CanCan::AuthorizationNotPerformed in AdminPanel::DashboardController#index HOT 1
- CanCan::AccessDenied exception HOT 1
- param is missing or the value is empty: activities HOT 1
- Role Infinite loop HOT 1
- CanCan is not allowing to initialize 2 users to have access to resources. Only one works at a time HOT 1
- Is CanCan being actively developed? HOT 2
- Question: How to load through parent of nested HOT 1
- How to differentiate permissions between admin/users_controller and users_controller
- Different exception messages for same pair of actions and subject
- Ability with conditions array behaving strangely for single objects
- before_filter deprecated
- Not loading expected results on :index action
- Update load_and_authorize_resource! "routing error before_filter" HOT 1
- Undefined Method exception when block is passed with curly braces
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cancan.