为什么此devise_group调用会出现NoMethodError? [英] Why am I getting NoMethodError for this devise_group call?

查看:80
本文介绍了为什么此devise_group调用会出现NoMethodError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用devise 3.5.2,ruby 2.2.2,rails 4.2.3

I'm using devise 3.5.2, ruby 2.2.2, rails 4.2.3

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  protect_from_forgery with: :exception

  devise_group :user, contains: [:manager, :employee]
end

我的理解是Devise应该加载这些帮助程序自动完成,我应该能够在ApplicationController中使用它们而无需做任何特殊的事情。

My understanding is that Devise should load these helpers automatically and I should be able to use them in ApplicationController without doing anything special.

我尝试运行带有 rails s的应用程序,我得到此错误:

I try and run the app with 'rails s' and I get this error:


multi-user-role-devise / app / controllers / application_controller.rb: 6:在
< class:ApplicationController>'中:未定义方法 devise_group'for
ApplicationController:Class(NoMethodError)from
/ home /me/ror-code/multi-user-role-devise/app/controllers/application_controller.rb:1:in
`'.... etc

multi-user-role-devise/app/controllers/application_controller.rb:6:in <class:ApplicationController>': undefined methoddevise_group' for ApplicationController:Class (NoMethodError) from /home/me/ror-code/multi-user-role-devise/app/controllers/application_controller.rb:1:in `' ....etc

我该如何解决?

Gemfile:

source 'https://rubygems.org'
ruby '2.2.2'
gem 'rails', '4.2.3'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'foundation-rails'
gem 'simple_form'
gem 'devise'
group :development do
  gem 'better_errors'
  gem 'quiet_assets'
  gem 'rails_layout'
  gem 'spring-commands-rspec'
end
group :development, :test do
  gem 'factory_girl_rails'
  gem 'faker'
  gem 'rspec-rails'
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end
group :test do
  gem 'capybara'
  gem 'database_cleaner'
  gem 'launchy'
  gem 'selenium-webdriver'
end

管理器类:

class Manager < User
end

员工类别:

class Employee < User
end


推荐答案

如果您仔细阅读了 Devise问题,您会发现遇到相同问题的人。最后,您会发现可能的 devise_permitted_pa​​rameters.rb 初始化程序阻止了所有Devise助手的正确加载。通过删除此初始化程序并在控制器中清除参数,可以解决该问题。

If you read through this Devise issue you will find people with the same problem. At the end, you will find out, that a possible devise_permitted_parameters.rb initializer prevents the correct loading of all Devise helpers. By removing this initializer and sanitizing your parameters within your controller should solve the problem.

同时,您可以在<$中添加 include Devise :: Controllers :: Helpers :: ClassMethods c $ c> ApplicationController ,但通常应避免这样的编码样式。

In the meanwhile, you can add include Devise::Controllers::Helpers::ClassMethods within your ApplicationController but you should avoid coding style like this in general.

这篇关于为什么此devise_group调用会出现NoMethodError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆