受保护的方法`授权!'呼叫#<admin :: customerscontroller:0x750c540> </admin :: customerscontroller:0x750c540>

时间:2014-07-12 16:11:38

标签: ruby ruby-on-rails-3 activeadmin cancan

我有这些问题确实让我感到烦恼 我尝试让activeadmin与CanCan合作。用户模型,我为不同的角色创建一个子类  用户&lt; - admin
 用户&lt; - 客户
等等

我完成了所有配置

config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.authentication_method = :authenticate_admin!
config.current_user_method = :current_admin

但是当我启动服务器时,我得到了这个:

  

未捕获的异常:未初始化的常量ActiveAdmin :: CanCanAdapter

为了摆脱这个错误我安装了宝石

  

gem&#39; activeadmin-cancan&#39;

现在一切都很好我可以看到activeadmin面板。但是当我添加资源时,资源没有显示在导航栏中,当我尝试直接访问它时,我得到了这个

  

受保护的方法`授权!&#39;呼吁#&lt;管理员:: CustomersController:0x750c540&GT;

如果你可以帮助我,我会非常感激!

这是Gemfile

source 'http://rubygems.org'
ruby '1.9.3'

gem 'rails', '3.2.17'
gem 'actionmailer', '3.2.17'

# sass-rails
gem 'sass-rails',   '>= 3.2'
# sass-rails depends on [sass (>= 3.1.10)]
gem 'sass', '3.2.8'  # Version 3.3.4 create error in Rake jobs:work
# bootstrap-sass
gem 'bootstrap-sass', '3.0.0'
# font-awesome
gem 'font-awesome-sass', '~> 4.0.2'

# CanCan is an authorization library for Ruby on Rails which
# restricts what resources a given user is allowed to access.
# https://github.com/ryanb/cancan/
gem 'cancancan', '1.8.2'
gem 'devise', '2.2.3'
gem 'devise-async', '0.7.0'
# Delayed_job (or DJ) encapsulates the common pattern of
# asynchronously executing longer tasks in the background.
gem 'delayed_job_active_record', '0.3.2'
#gem 'dj_mon', :git => 'git://github.com/jrosesol/dj_mon.git'

# HStore gem (to use NO SQL)
gem 'activerecord-postgres-hstore', '0.4.1'#git: 'git://github.com/softa/activerecord-postgres-hstore.git',
# Geocoder gem to place requests to Google's MAP API
gem 'geocoder', '1.1.8'
# Google place API implementation
# https://github.com/marceldegraaf/google_places
gem 'google_places', '0.18.0'
# Bundles some javascript files to make them available to your application backbone/underscore/json2
# https://github.com/aflatter/backbone-rails
gem "rails-backbone", "0.7.2"
#################
# RABL (Ruby API Builder Language) is a Rails and Padrino ruby templating system for generating JSON, XML, MessagePack, PList and BSON.
# https://github.com/nesquena/rabl
#
#gem 'rabl', '0.7.9'
# Also add either `oj` or `yajl-ruby` as the JSON parser
#gem 'oj', '1.4.6'
#################

# Easiest way to add multi-environment yaml settings to Rails3
# https://github.com/railsjedi/rails_config
gem 'rails_config', '0.3.3'

# Using Postgres database gem
gem 'pg', '0.14.1'
#
gem 'will_paginate', '3.0.3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  #gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer'

  gem 'uglifier', '>= 1.0.3'
end

# jQuery JavaScript Library v1.8
gem 'jquery-rails', '2.1'

# TODO:  Should be in the 'TEST' group but there is a bug fixed in rubymine 5.0, change when possible
# http://youtrack.jetbrains.com/issue/RUBY-12632
gem 'rspec', :require => false

group :development, :test do
  gem 'rspec-rails', '2.12.2'
  gem 'capybara', '2.0.2'
  gem 'launchy', '2.2.0'
  gem 'annotate', '~> 2.4.1.beta'
  gem 'quiet_assets', '1.0.2'
  gem 'factory_girl', '4.2.0'
  gem 'database_cleaner'
  gem 'shoulda'
  # Generate fake data for your project test
  gem 'faker', '1.0.1'
  gem 'i18n-tasks', '~> 0.3.11' #Simplifying Translations
  gem 'simplecov', '0.8.2' #to have the coverage for the tests

end

# Add CSS inline for outgoing email (requires Bundler 1.2 pre+))
gem 'premailer-rails', '1.7'

# Daemon is require to run delayed_jobs scripts in Unix systems
gem 'daemons', '1.1.9'

# Captcha for wizard
gem "recaptcha", '0.3.5', :require => "recaptcha/rails"


# For search engine indexing (Sitemap.xml)
gem 'sitemap_generator', '4.2.0'

# This is for crawling/webscraping
#https://github.com/fizx/robots
gem 'robots', '0.10.1'
#http://nokogiri.org/
gem 'nokogiri', '1.6.2.1'
#https://github.com/chriskite/anemone/tree/master
gem 'anemone', '0.7.2'

# Application monitoring
gem 'newrelic_rpm', '3.9.0.229'

# For passing data to javascript files
gem 'gon', '5.0.4'

# For autocomplete-search boxes
gem 'select2-rails', '3.5.7'

gem 'json', '1.8.1'

platform :ruby do #linux only
  group :production, :staging do
    gem 'unicorn', '4.8.3'
  end
end

# These are used to store the logo of a company into s3 amazon
gem 'paperclip' , '4.1.1'
gem 'aws-sdk'   , '1.43.2'

gem 'activeadmin'
gem 'meta_search'
gem 'activeadmin-cancan'

1 个答案:

答案 0 :(得分:2)

使用gem 'cancancan'代替gem 'cancan',删除gem 'activeadmin-cancan',您不必使用该gem。不要忘记更新你的宝石:bundle update