undefined local variable or method `authenticate_admin'

后端 未结 1 628
北恋
北恋 2021-01-28 06:02

I\'m trying to view my new action in my blogs controller, but I keep getting the following error message:

NameError in BlogsController#new
undefined local variab         


        
相关标签:
1条回答
  • 2021-01-28 06:41

    In this case Helpers are accessible in your Views not in Controllers.

    Solution is to move your methods from admins_helper.rb to ApplicationController and set them as helper_methods. You will be able to access them in your Controllers and Views.

    Example:

    class ApplicationController < ActionController::Base
    
      # Helpers
      helper_method :authenticate_admin
    
      def authenticate_admin
        deny_admin_access unless admin_signed_in?
      end 
    
    end
    

    Read documentation about helper_method:

    http://api.rubyonrails.org/classes/AbstractController/Helpers/ClassMethods.html#method-i-helper_method

    0 讨论(0)
提交回复
热议问题