Why helper devise_controller? returns false for the following code:

 class ApplicationController < ActionController::Base protect_from_forgery with: :exception layout :resource protected def resource if devise_controller? #"admin" puts "admin" else #"application" puts "app" end end end 

while in the browser line, go to " http://127.0.0.1ل000 / admin / review "

routes.rb file:

  Rails.application.routes.draw do get 'admin/show' get 'admin/upload' get 'admin/review' get 'welcome/index' get 'welcome/portfolio' get 'welcome/about' get 'welcome/contact' get 'welcome/blog' get 'welcome/review' end 

while for other routes get 'admin / show'and get' admin / upload 'the helper returns true ....

Update

In general, the problem was solved like this. Added a filter to ApplicationController

 before_filter :my_filter, unless: :devise_controller? def my_filter if params['controller'] == 'admin' render layout: "admin" end end 

But the question essentially remains - why does the same malfunction work through the layout ?

  • Add Admin Controller Code - Sergei Stralenia

1 answer 1

Method devise_controller? just checks if your class DeviseController from the DeviseController class

 def devise_controller? is_a?(::DeviseController) end 

Your controller inherits from ActionController::Base , so the condition can not always be satisfied. To check the fact of authentication, it is better to use Devise helpers: user_signed_in? and current_user . If you need to change the layout, regardless of whether the user is authenticated or not, just change it in render (as you actually did in the Update).