在Devise中跳过身份验证时未定义的方法`skip_before_action'

Pro*_*rox 0 ruby ruby-on-rails devise

我正在使用本指南在Rails中设置Devise:http: //codepany.com/blog/rails-5-user-accounts-with-3-types-of-roles-devise-rails_admin-cancancan/

它表示将其放在您的家庭控制器上以防止Devise在您的主页上请求身份验证:

skip_before_action :authenticate_user!, :only => [:index]
Run Code Online (Sandbox Code Playgroud)

我的家庭控制器叫dev,所以我的dev_controller.rb看起来像这样:

class DevController < ApplicationController
  def index

  skip_before_action :authenticate_user!, :only => [:index]

  end
end
Run Code Online (Sandbox Code Playgroud)

现在,当我访问我的网站时,我收到此错误:

undefined method `before_action' for #<MenuController:0xb193b640>
Run Code Online (Sandbox Code Playgroud)

关于我为何会收到此错误的任何想法?

Raj*_*Das 5

请尝试以下

skip_before_action应该是index方法范围的一面.作为before_action或是skip_before_action一种类方法.不应该在实例方法(索引)中调用它

class DevController < ApplicationController
 skip_before_action :authenticate_user!, :only => [:index]

  def index
  end
end
Run Code Online (Sandbox Code Playgroud)

参考