cancan

Devise role based routing

半世苍凉 提交于 2019-12-07 23:56:24
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 want to keep them from being able to visit any of my other paths ie: domain.com/calls domain.com/units I

Adding a Controller without corresponding model while using cancancan

旧巷老猫 提交于 2019-12-07 21:19:53
问题 I've added a controller collaborators to manage a particular type of join association between Users and Companies . The issue is that whenever I load anything from collaborators , I get the error uninitialized constant Collaborator From my understanding, this is because there is no model Collaborator and I am using cancancan for authorization. From the old cancan (note not cancancan) documentation, I've been able to gather that controllers that don't have a corresponding model need to have a

Rails: Using CanCan to define multiple roles depending on instances of single Model?

与世无争的帅哥 提交于 2019-12-07 01:07:35
问题 I'm currently stuck on how to separate roles for CanCan depending on each condition that we want. In our application, there are many categories (such as math, english, history, etc.) and within each are many courses. Each user can have many different roles on each category. For example, John can be a "reader" for math, which means he can read all the courses that are in math. John can also be a "writer" for english, which means he can read all the courses in english, create a course within

Allow users to edit/destroy their own profiles only from the index

久未见 提交于 2019-12-06 15:55:11
问题 How do I grant permission to edit/ destroy links on a by-user basis in the user index of rails? I'm using Rails3, Devise and CanCan to define role based abilities. I'd like the current user to be able to see and access a link to edit/delete their profile in the user index page. They should not be able to see or access these links for all other users. I've set up the following in the index view: <% if can? :update, @user %> <%= link_to 'Edit', edit_user_registration_path(@user) %> | <% end %>

ActiveModel::ForbiddenAttributesError + cancan + rails 4 + model with scoped controller

蓝咒 提交于 2019-12-06 07:30:29
问题 I m using cancan(1.6.10) with rails 4.0.0. I have a model called 'App'(not scoped) and a controller Admin::AppsController(its scoped. ie app/controllers/admin/apps_controller). the controller code is as class Admin::AppsController < ApplicationController before_filter :authenticate_user! load_and_authorize_resource class: App def index end #CRUD methods and some other custom methods ... private def app_params params.require(:app).permit(:name, :description, :author, :url_path, :validated,

Adding a Controller without corresponding model while using cancancan

不羁的心 提交于 2019-12-06 05:02:19
I've added a controller collaborators to manage a particular type of join association between Users and Companies . The issue is that whenever I load anything from collaborators , I get the error uninitialized constant Collaborator From my understanding, this is because there is no model Collaborator and I am using cancancan for authorization. From the old cancan (note not cancancan) documentation , I've been able to gather that controllers that don't have a corresponding model need to have a model manually authorized for them something like: load_and_authorize_resource :the_model, :parent =>

Rails_admin: Should I have admin_user or user with admin role to manage users and admin panel

馋奶兔 提交于 2019-12-06 02:10:43
问题 In my rails application website visitors can sign up and create content. It uses devise with user model and everything works well. Now I want to use rails_admin for managing website resources and users etc and only people with administrative previllages should be able to access it. Should I create a separate AdminUser model for admin panel access or use User model with role of admin, and use some authorization library to manage access. If I user only one model then I want users to be

CanCan - Access denied - Way to make CanCan Specify in the LOG Why?

橙三吉。 提交于 2019-12-05 23:59:27
问题 I'm working to implement CanCan. For some reason CanCan keeps giving me Access Denied when I try to get specific about model permissions. And I can't figure out why. Is there a way to get CanCan to be specific, perhaps in the logs or in development about Why Access is denied? something like, No Read Ability to XXX Model. That would be helpful for debugging. Thanks 回答1: You can add a rescue_from block in ApplicationController to handle CanCan exceptions and set your custom error message there.

Passing params to CanCan in RoR

佐手、 提交于 2019-12-05 23:49:30
问题 I have a controller with a method like; def show if params[:format].eql?("pdf") // do something elsif params[:format].eql?("csv") // do something end end But i have users with different roles. So i use CanCan to manage access control. Now i want X role can do the action show in controller iff params[:format].eql?("csv") I think it can be like ; can :show, resource if params[:format].eql?("csv") . So how can i send parameters to ability.rb? Any idea? Thanks. 回答1: In ApplicationController add

Devise, Rolify and Cancan to ActiveAdmin

谁说胖子不能爱 提交于 2019-12-05 13:25:42
I am developing an app using Devise, Rolify and CanCan. Can I shift it completely to be administered by ActiveAdmin. Is there any documentation for that? I know it's been a while since the question was asked... but as I found it while doing a google search, I think I can post an answer to help others. So! There is a documentation to make ActiveAdmin use Cancan for its authentication and authorization system. Here is a very simple how to add a CancanAdapter in ActiveAdmin In fact they even explain how to create your own Authorization Adapter. And yeah, Rolify does have a good documentation on