【发布时间】:2011-05-19 05:26:12
【问题描述】:
已解决:我在 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}'"}
我正在使用具有以下设置的设计:
导轨:3.1,设计: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
谢谢!
【问题讨论】:
-
如果你删除了 if user_signed_in?登录后调用 current_user.email 吗?
-
不,'current_user' 的相同错误(未定义)=/
-
您是否通过应用程序进行了身份验证?
-
是的,我只能访问这个经过身份验证的控制器,你如何在路由中看到。我认为问题是在身份验证方法之前加载了布局,因为如果我可以重新加载 Ruby 代码,它就会运行。
-
你能用你的解决方案创建一个答案并接受它吗?这样其他有类似问题的人都会从你的痛苦中受益:)
标签: ruby-on-rails devise ruby-on-rails-3.1