Questions tagged [cancancan]

Continuation of CanCan, the authorization Gem for Ruby on Rails.

As in the project webpage:

CanCanCan is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in a single location (the Ability class) and not duplicated across controllers, views, and database queries

453 questions
0
votes
0 answers

Cancan and cancancan gem both acting weird

I was playing with cancan gem. I tried to implement it in a rails 4.2.1 project. My ruby version 2.2.3. These are the two gems I just installed gem 'devise', '~> 3.5', '>= 3.5.2' gem 'cancan', '~> 1.6', '>= 1.6.10' I configured cancan gem and…
asdfkjasdfjk
  • 3,784
  • 18
  • 64
  • 104
0
votes
2 answers

Allowing non-admin to create order in spree backend

I would like to create a role which is not the admin that can create order in the spree backend, but I couldn't find the combination of actions that I need to activate for that user. I tried adding the default user permission and allow role to…
harinsa
  • 3,176
  • 5
  • 33
  • 53
0
votes
1 answer

How to excute the below code? from CanCan Abilities in Database

I got this from here, but I don't know where to put and how I will execute this. I tried to create class and run this thru console (rails c) but it is not working. def setup_actions_controllers_db write_permission("all", "manage", "Everything",…
do_Ob
  • 709
  • 1
  • 6
  • 24
0
votes
1 answer

Rails cancancan gem with sequenced gem

Building rails app. I am using cancancan for authorization and sequenced gem for using sequence number instead of real ID's. (For nice urls and simpler ID's). Now when the url is e.g. /customers/1 Cancancan is loading customer with ID=1 instead of…
Muhammad Usman
  • 358
  • 2
  • 10
0
votes
1 answer

CanCan Ability: can read Class if he can read at leas one Object of class

In cancan to be Able to :read all User for exemple we need can :read,User to be able to see a specific instance of the user we need can :read, User do |user| user == something (condition satisfied ==> ability satisfied) end Now my question is…
0
votes
1 answer

Rails CanCanCan - Defining Abilities - using end statements and referencing objects (model or table names)

I am trying to make an app with Rails 4. I use CanCanCan for abilities and Role_Model for roles. I am having a difficult time in finding the basic rules for conditional statements. I don't understand how many 'ends' you need after an 'if/elsif/else'…
Mel
  • 2,481
  • 26
  • 113
  • 273
0
votes
1 answer

Rails CanCanCan & Defining Abilities

I am trying to make an app in Rails 4. I am using CanCanCan for permissions and Role_Model for roles management. In my ability.rb, I have defined student abilities as: elsif user.try(:profile).present? && user.profile.has_role?(:student) …
Mel
  • 2,481
  • 26
  • 113
  • 273
0
votes
1 answer

how set the permissions for cancan gem?

please help solve the problem. i try set the permissions after install 'cancan' and 'cancancan' gems. schema.rb: create_table "roles", force: :cascade do |t| t.string "name" end create_table "roles_users", id: false, force: :cascade do |t| …
stackow1
  • 301
  • 1
  • 3
  • 10
0
votes
2 answers

Rails - ActiveAdmin & CanCan custom override method for initialize_cancan_ability

I am attempting to pass thru request data to the Ability model as suggested here: class ApplicationController < ActionController::Base #... private def current_ability @current_ability ||= Ability.new(current_user, request.remote_ip) …
kayatela
  • 394
  • 5
  • 21
0
votes
2 answers

CanCanCan Rails Not Working

I am using Rails 4 with Devise and CanCanCan, and for some reason when I try to give users CRUD permissions only for products that they have made, none of the CanCanCan permission settings go through and users can only do read only. However, the…
aishaq11
  • 179
  • 1
  • 1
  • 16
0
votes
1 answer

Rails 4 - cancancan - defining abilities

Is it possible to define a CanCanCan ability by reference to another ability? For example, I have models called Project and Project Question. I want to allow a class of users to read projects and then if they can read the projects then they can…
Mel
  • 2,481
  • 26
  • 113
  • 273
0
votes
1 answer

Testing cancancan abilities with rspec

I am trying to test my cancancan abilities using rspec but as opposed to testing for what a particular user can do, I am trying to test for what a user should not be able to do. Now, I have a block of context like so: context "for a manager" do …
x6iae
  • 4,074
  • 3
  • 29
  • 50
0
votes
1 answer

Rails 4 & CanCanCan - syntax

I am trying to use CanCanCan to define abilities in my Rails 4 app. I have this ability in my ability.rb file: can :read, Proposal, { :expiry_date > Time.now, :sweep => { :disclosure => { :allusers => true } } } syntax error,…
Mel
  • 2,481
  • 26
  • 113
  • 273
0
votes
0 answers

Rails 4, Devise, Role Model and CanCanCan

I'm trying to figure out how to define cancancan abilities in my rails 4 app. I use devise for authentication. When I try: if user_signed_in? can :crud, Profile, :user_id => user.id #[for themselves] I get an error that says: undefined…
Mel
  • 2,481
  • 26
  • 113
  • 273
0
votes
1 answer

Rails Devise Role Model & CanCanCan - defining abilities

I'm trying to define abilities in CanCanCan. I can't figure out the syntax to get started. I use Role Model for my roles and the roles are defined in my Profile.rb. Profile.rb belongs to User.rb. I am trying to check if the user has the role…
Mel
  • 2,481
  • 26
  • 113
  • 273