3

已解决:我在 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

谢谢!

4

3 回答 3

2

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

于 2011-08-24T03:35:02.130 回答
1

听起来您尝试调用的函数未定义。当您运行 rails g devise User 时,您将获得您正在尝试使用的功能,但是如果您使用非标准的东西,您需要使用它的单数版本。因此,如果您运行 rails g devise somethingnonstandard,您将拥有 somethingnonstandard_logged_in 的功能?等等等等

于 2011-05-19T05:49:18.513 回答
1

ApplicationController 中的“clear_helpers”方法阻止了 Devise 加载他的助手。

所以我删除了这个方法并且应用程序正常工作。

于 2011-05-20T12:24:47.317 回答