0.0
No commit activity in last 3 years
No release in over 3 years
cancan ability for views
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.6.0

Runtime

~> 1.6.7
 Project Readme

#cancan_edit cancan_edit is a gem for your views, in which you can disable and/or enable fields based on permissions.

##Installation

$  gem install cancan_edit

##How to use?

let's assume you have Person model with

first_name, text_field, 
last_name, text_field,
address, textarea,
is_admin, checkbox

and you are using cancan for authorization with admin photo_editor groups.

you want an admin group to be able to edit all fields and all models.

  can_edit :manage, :all

you want an admin group to be able to change "is_admin" checkbox but not photo_editor.

  class Ability
    include CanCan::Ability
    include CanCan::EditAbility
  
    def initialize(user)
      if user.is?("admin")
        can_edit :manage, Person
      elsif user.is?("photo_editor") 
        can_edit :manage, Person
        cannot_edit [:is_admin] , Person
      end
    end
  end

you can also

  can_edit [:first_name, :last_name ], [Person]

or

  cannot_edit [:is_admin ], [Person]