未定义的方法“user_signed_in?” - 设计
已解决:我在 ApplicationController 中使用了“clear_helpers”方法,因此它阻止了 Devise 加载他的助手。
您好,
当我第一次在“开发”模式下运行我的应用程序时,我收到此错误,当我重新加载时,错误消失了。当我在“生产”上运行时,错误仍然存在,因为生产仅加载应用程序一次(?),那么发生了什么?有人可以帮忙吗?
错误:
undefined method `user_signed_in?' for #<#<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}'"}
我使用 Devise 进行以下设置:
Rails:3.1,Devise:1.3.4
我的模型:
class User::Account < ActiveRecord::Base
devise :database_authenticatable, :confirmable, :lockable, :recoverable,
:rememberable, :registerable, :trackable, :timeoutable, :validatable,
:token_authenticatable
end
路线:
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
我的控制器:
class Main::CockpitController < ApplicationController
before_filter :authenticate_user!
def index
end
end
谢谢!
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 #<#<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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我收到此错误是因为我用我的设计路线做了一些奇怪的事情。让它们变得正常为我解决了这个问题。
I got this error because I was doing some weird stuff with my devise routes. Making them normal solved it for me.
听起来您尝试调用的函数未定义。当您运行 Rails g devise User 时,您将获得您尝试使用的功能,但是如果您使用了非标准的功能,则需要使用该功能的单数版本。那么,如果你运行rails g devise somenonstandard,你会有函数somethingnonstandard_logged_in吗?等等等等
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.
ApplicationController 中的“clear_helpers”方法阻止 Devise 加载其助手。
所以我删除了这个方法并且应用程序可以工作。
The method 'clear_helpers' in ApplicationController was blocking Devise to load his helpers.
So I removed this method and app works.