cancan

Setting up different User models and registration paths for Devise on Ruby on Rails

纵饮孤独 提交于 2019-12-09 23:27:31
问题 I am very new to ruby and I have been really struggling with this for months. I searched extensively and tried what the answers said but still no luck. (I tried Multiple user models with Ruby On Rails and devise to have separate registration routes but one common login route but didnt work) I currently have a user.rb model and it is connected to devise and works fine. 1- On the sign-up page, I would like to have 3 buttons that would lead to separate registration forms (one each for business,

Devise/CanCanCan - Allow Admin To Create New Users

孤者浪人 提交于 2019-12-09 22:58:27
问题 I'm using rails 4.0.2, devise and cancancan. I'm trying to allow an admin to create new users. Admin users are assigned with a boolean field in the users table. In ability.rb I have the following: can :manage, :all if user.admin? Following some of the advise in this question I created a new controller called AdminsController and it looks like so: class AdminsController < Devise::RegistrationsController def create build_resource(sign_up_params) if resource.save redirect_to admin_editors_path

CanCan load_and_authorize_resource triggers Forbidden Attributes

北战南征 提交于 2019-12-09 08:28:15
问题 I have a standard RESTful controller that uses strong parameters. class UsersController < ApplicationController respond_to :html, :js def index @users = User.all end def show @user = User.find(params[:id]) end def new @user = User.new end def edit @user = User.find(params[:id]) end def create @user = User.new(safe_params) if @user.save redirect_to @user, notice: t('users.controller.create.success') else render :new end end def update @user = User.find(params[:id]) if @user.update_attributes

Spree Custom Roles Permissions

本小妞迷上赌 提交于 2019-12-09 07:05:13
问题 I am trying to give some custom roles within spree specific permissions. Cant find this answer anywhere role_ability.rb class RoleAbility include CanCan::Ability def initialize(user) user || User.new # for guest if user.has_role? "admin" can :manage, :all elsif user.has_role? "retailer" can :manage, Product else can :read, :all end end end I thought this might be a popular idea, of letting a user with role 'manager' manage only products and other certain Models... if I change elsif user.has

Cancan + Devise rescue_from not catching exception

六眼飞鱼酱① 提交于 2019-12-08 21:38:42
I am implementing Devise and Cancan for user authentication and permissions. Everything works great so far except I am not able to redirect users to the login page when they are not allowed to access a specific feature. My test is: feature 'A signed in user' do before(:each) do user = FactoryGirl.create(:user) visit "/login" fill_in "user_email", :with => user.email fill_in "user_password", :with => "ilovebananas" click_button "Sign in" end scenario 'should not have access to admin dashboard' do visit '/admin' page.should have_content 'Log in' end end And I get the following failure: Failures:

ActiveAdmin + CanCan + AASM event switcher with AJAX

你离开我真会死。 提交于 2019-12-08 12:37:07
问题 As an admin I have a specific role I want to see and switch event for object Depends on my role Inspired by activeadmin_addons and its Enum Integration I want to make similar functionality for AASM by letting diffent admin users change events depending on their abilities/roles for specific events/statuses in model. 回答1: Taken from here, please see this link for additional files you need Prequestites: Gem: ActiveAdmin, Gem 'active_admin_role', both are installed and working AdminUser model

using cancan getting undefined local variable or method `roles'

时光总嘲笑我的痴心妄想 提交于 2019-12-08 10:02:44
问题 I've given up on trying to lock down every action in the application. Currently I'm placing in every controller except the devise/registration: load_and_authorize_resource in the user model: def role?(role) roles.include? role.to_s end in the ability model: if user.role? :superadmin can :manage, :all end However, I am getting the following error: undefined local variable or method `roles' app/models/user.rb:33:in `role?' app/models/ability.rb:7:in `initialize' Thanks for your help. UPDATE:

Cancan condition

好久不见. 提交于 2019-12-08 09:33:47
问题 I'm using CanCan in a project to manage different role level on each entity for each project. I'm doing this: # encoding: utf-8 class Ability include CanCan::Ability def initialize(user) user ||= User.new if user.is_admin == true can :manage, :all else can :read, :all Project.all.each do |project| current_role_name = user.roles.find_by_project_id(project.id).role_name.name if current_role_name.eql?'Auteur senior' can :manage, [Project, Introduction, Abstract, Text, Conclusion, Asset,

Devise role based routing

北城余情 提交于 2019-12-08 08:45:12
问题 I have an app with multiple users. Each user as a theoretical role (user, client, etc). I've designed a view/controller for each user type. I want to be able to login each type of user do a different root url and lock them to it. Originally I was going to add a column to Users in Devise called role and so I can differentiate the users. The problem I'm having is how to say in routes.rb if current_user.role == "client" root :to => 'controller#index' Once they are logged in to the page I also

Cancan nested_routes restrict acces to :index

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 01:49:12
问题 I have some problems with cancan and a nested routes. I have this routes : resources :companies do resources :projects end I have no problem with the abilities for Company model but for the Project model I want to deny the access to Project#index if they are not admin of the company. The next code works : can :show, Company do |company| if user.admins.include?(company) #check if the user is admin of the company can :index, Schedule, :company_id => company.id end end But how I can do : can?