Devise Layouts for SignedIn & Signed Out resources
My App has two UI states: - Signed IN - Signed Out
I've been using the following to determine which app/view/layout to use based on if the user is signed in or out with Devise:
  # Devise, way of using a different Layout for all the devise/non-signed in Views
  layout :layout_by_resource
  def layout_by_resource
    if devise_controller?
      "application_unauthorized"
    else
      "application"
    end
  end
The problem is once your signed in it uses the wrong layout? ideas?
I only want to use "application_unauthorized" if i开发者_开发技巧t's devise & the user is not signed in.
Actually you should use the user_signed_in? method to check if the user is signed in. I noticed that current_user? might return true even if the user is currently not signed in.
So your code would look something like this:
layout :layout_by_resource
def layout_by_resource
  if user_signed_in?
    "application"
  else
    "application_unauthorized"
  end
end
Personally I would check using if current_user? rather than devise_controller?
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论