undefined method `user_signed_in?' - Devise
SOLVED: Im was using the method 'clear_helpers' in ApplicationController, so it was blocking Devise to load his helpers.
Hello,
When I run my application in the first time on 'development' mode, I get this error, when I reload the error desapear. When I run on 'production' the error still, because production loads application only one time (?), so what is happening? Someone can help?
Error:
undefined method `user_signed_in?' for #开发者_如何学Go<#<Class:0x10312ddc0>:0x103127100>
Extracted source (around line #16):
13:
14: #top
15: = link_to '', root_path, :id => 'logo'
16: - if user_signed_in?
17: #session
18: %p= raw "Olá <b>#{current_user.email}</b>"
19: #myaccount.button{:onclick => "javascript: document.location.href = '#{edit_user_registration_path}'"}
Im using Devise with following setup:
Rails: 3.1, Devise: 1.3.4
My model:
class User::Account < ActiveRecord::Base
devise :database_authenticatable, :confirmable, :lockable, :recoverable,
:rememberable, :registerable, :trackable, :timeoutable, :validatable,
:token_authenticatable
end
Routes:
Foco::Application.routes.draw do
devise_for :users, :class_name => 'User::Account'
root :to => 'main/cockpit#index', :constraints => lambda {|r| r.env["warden"].authenticate? }
devise_scope :user do
root :to => "devise/registrations#new"
end
end
My controller:
class Main::CockpitController < ApplicationController
before_filter :authenticate_user!
def index
end
end
Thanks!
I got this error because I was doing some weird stuff with my devise routes. Making them normal solved it for me.
It sounds like the functions you are trying to call are not defined. When you run rails g devise User you get the functions that you are trying to use, however if you used something nonstandard you need to use the singular version of that. SO if you ran rails g devise somethingnonstandard you would have the functions somethingnonstandard_logged_in? etc. etc.
The method 'clear_helpers' in ApplicationController was blocking Devise to load his helpers.
So I removed this method and app works.
精彩评论