I am using gem 'devise' for authentication in my project. Everything was fine but after adding gem 'cancancan' in my gemfile. Then I logged in as a user for test my app and saw this "NameError at / uninitialized constant Main".
project gemfile:
gem 'devise'
gem 'carrierwave'
gem 'bootstrap-sass'
gem 'cancancan'
gem 'better_errors
project models:
ability.rb file:
class Ability
include CanCan::Ability
def initialize(user)
end
end
user.rb file:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,:confirmable,
:recoverable, :rememberable, :trackable, :validatable
end
project controller: main_controller.rb file
class MainController < ApplicationController
load_and_authorize_resource
def index
end
def me
end
end
where am I doing wrong? Please give me your advice.
Thanks, Mezbah
load_and_authorize_resource method is provided to automatically authorize all actions in a RESTful style resource controller
你只是没有Main
模型
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.