未定义的方法“user_signed_in?” - 设计

发布于 2024-11-07 20:24:23 字数 1564 浏览 2 评论 0原文

已解决:我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悍妇囚夫 2024-11-14 20:24:23

我收到此错误是因为我用我的设计路线做了一些奇怪的事情。让它们变得正常为我解决了这个问题。

I got this error because I was doing some weird stuff with my devise routes. Making them normal solved it for me.

指尖上得阳光 2024-11-14 20:24:23

听起来您尝试调用的函数未定义。当您运行 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.

蝶…霜飞 2024-11-14 20:24:23

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文