【问题标题】:Rails3/Devise: undefined method new_application_user_session_pathRails3/Devise:未定义的方法 new_application_user_session_path
【发布时间】:2010-11-03 21:11:57
【问题描述】:

按照 README 文档,我将 Devise 安装到现有的 Rails 3 应用程序中。但是,它似乎不起作用。当我尝试访问具有before_filter :authenticate_application_user! 的控制器之一时,我收到以下错误消息:

undefined method 'new_application_user_session_path' for #<Devise::FailureApp::0x60aldc0>

我不知道为什么。我检查了很多,看看我是否正确地遵循了安装指南,但无济于事。所以我想知道是否有人冷帮我。

这是我的routes.rb

AwesomeApp::Application.routes.draw do

  devise_for :application_users

  root :to => "home#index"  

  scope "admin" do
    resources :application_users, :path => "users"    
  end
end

这是我的Gemfile

source 'http://rubygems.org'

gem 'rails', '3.0.0'

gem 'ruby-oci8'
gem 'activerecord-oracle_enhanced-adapter'
gem 'warbler'

gem 'devise', '1.1.3'

group :development, :test do
  gem 'factory_girl_rails'
  gem 'forgery'
end

这是我用于更新现有数据库架构的迁移文件:

class DeviseCreateApplicationUsers < ActiveRecord::Migration
  def self.up
    change_table(:application_users) do |t|
      t.rememberable
      t.trackable
    end

  end

  def self.down
    change_table(:application_users) do |t|
      t.remove :rememberable, :trackable
    end
  end
end

注意:如果有人想知道,我将使用 LDAP 进行身份验证。所以这就是为什么你看不到t.database_authenticatable

这是我的模型application_user.rb

class ApplicationUser < AbstractModel

  devise :rememberable, :trackable, :timeoutable  

end

这是我的 devise.rb 初始化文件:

Devise.setup do |config|
  config.mailer_sender = "please-change-me@config-initializers-devise.com"
  require 'devise/orm/active_record'
  config.authentication_keys = [ :user_ldap_id ]
  config.stretches = 10
  config.encryptor = :bcrypt
  config.pepper = "SALT AND PEPPERS HERE, SALT SALT SALT"
end

注意:因为我将针对 LDAP 进行身份验证,所以我使用的列不同于 Devise 默认使用的默认 email 列。结果,我不得不安装 Devise 视图 (rails g devise:views) 并修改 app/views/devise/session/new.html.erb 文件以使用 user_ldap_id 而不是 email

注意:我从这些 sn-ps 中删除了所有不相关的代码。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 ldap devise


    【解决方案1】:

    问题是因为我的模型中没有启用database_authenticable。没有它,将不会生成任何路线。但因为我不需要它,所以没有意义。但是,为了解决这个问题,我必须安装 Devise LDAP Authenticatable 并在我的模型中启用它。一旦我这样做并重新启动服务器,该路由就可以访问了。

    看看我在 Devise Github 存储库上创建的这张票。那里有人能够引导我完成整个事情。他们的反应速度令人印象深刻。

    https://github.com/plataformatec/devise/issues/issue/614/#comment_517418

    在我的 Gemfile 中添加了以下内容:

    gem 'devise_ldap_authenticatable'
    

    在我的 application_users.rb 中添加了以下内容:

    devise :ldap_authenticatable
    

    【讨论】:

      猜你喜欢
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      相关资源
      最近更新 更多