简体   繁体   中英

Rails cancancan uninitialized constant Ability::Dashboard Did you mean? DashboardHelper

I've a little problem with cancancan. I'd like check user's rights to access at his profile and admin dashboard. I've follow a tutorial who explain how use cancancan but I've this error on admin dashboard

uninitialized constant Ability::Dashboard Did you mean? DashboardHelper

Dashboard is my profile controller. If I remove dashboard's check in ability the error disappear. I've tried to find a solution on internet but nothing has solved my problem

Thanks for your help

The code is on github

https://github.com/remibovin/cancancan_project

Your problem is there is no Dashboard class in your application. I think the best way to go forward is in your Controller use:

class DashboardController < ApplicationController
  authorize_resource :class => false
  def index
  end

and you can authorize the controller with a symbol in your Ability.rb file like so:

can :manage, :dashboard, user_id: user.id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM