Why does a helper "devise_controller?" return false for my code?
Why is helper?
falsefor 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 ♪
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...
That's the kind of problem. Added to
before_filter :my_filter, unless: :devise_controller?
if params['controller'] == 'admin'
render layout: "admin"
But the substantive question remains - why
layoutDoes it work the same way with malfunctions?
morde last edited by
devise_controller?Just checking if your class is inherited.
def devise_controller? is_a?(::DeviseController) end
You've got a controller coming from you.
ActionController::Baseso the condition cannot always be met. In order to verify the authentication, it is best to useper Devise:
current_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).