【发布时间】: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