Why does a helper "devise_controller?" return false for my code?
-
Why is helper?
devise_controller?
returnsfalse
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
And in the browser line, it's a " http://127.0.0.1:3000/admin/review ♪
file routes.rb:
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
And for the rest of the routes get 'admin/show' and get 'admin/upload', the helper gives true...
Updating
That's the kind of problem. Added to
ApplicationController
filterbefore_filter :my_filter, unless: :devise_controller?
def my_filter
if params['controller'] == 'admin'
render layout: "admin"
end
end
But the substantive question remains - why
layout
Does it work the same way with malfunctions?
-
Method
devise_controller?
Just checking if your class is inherited.DeviseController
def devise_controller? is_a?(::DeviseController) end
You've got a controller coming from you.
ActionController::Base
so the condition cannot always be met. In order to verify the authentication, it is best to useper Devise:user_signed_in?
andcurrent_user
♪ If you need to change the layout regardless of whether the user is authenticated or not, just change it to render it (as you did in the Innovation).