Following the README documentation, I installed Devise into an existing Rails 3 application. However, it doesn’t seem to work. When I try to access one of my controllers that have before_filter :authenticate_application_user!, I get the following error message:
undefined method 'new_application_user_session_path' for #<Devise::FailureApp::0x60aldc0>
I have no idea why. I’ve checked numerous to see if I followed the installation guide correctly, to no avail. So I’m wondering if anyone cold help me out.
Here is my 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
Here is my 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
Here is my migration file for updating my existing database schema:
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
NOTE: In case anyone is wondering, I will be authenticating using LDAP. So that’s why you don’t see t.database_authenticatable
Here is my model application_user.rb:
class ApplicationUser < AbstractModel
devise :rememberable, :trackable, :timeoutable
end
Here is my devise.rb initializer file:
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
NOTE: Because I will be authenticating against LDAP, I am using a different column other than the default email column that Devise defaults to. As a result, I had to install the Devise views (rails g devise:views) and modify the app/views/devise/session/new.html.erb file to use user_ldap_id instead of email.
NOTE: I removed any irrelevant code from these snippets.
The problem was because I did not have the
database_authenticableenabled in my model. Without that, no routes will be generated. But because I don’t need it, there was no point. However, to resolve this issue, I had to install Devise LDAP Authenticatable and enabled it in my model. Once I did that and restarted the server, the route became accessible.Take a look at this ticket I created on the Devise Github repo. Someone there was able to walk me through the entire thing. Quite impressed actually at how responsive they were.
https://github.com/plataformatec/devise/issues/issue/614/#comment_517418
Added the following to my Gemfile:
Added the following to my application_users.rb: