Giter VIP home page Giter VIP logo

Comments (3)

pacoguzman avatar pacoguzman commented on June 2, 2024

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.

fespinoza avatar fespinoza commented on June 2, 2024

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.

fespinoza avatar fespinoza commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.