Reputation: 13
I'm using devise for authenticating users in my app. The problem is that none of the devise helpers exist in my app. For example. In file app/controllers/admin/dashboard.php
I have this snippet of code:
<% if user_signed_in ? %>
do something
<% end %>
I get
undefined method `user_signed_in?'
Here is the output of the rake routes
command
new_admin_session GET /admin/sign_in(.:format) devise/sessions#new
admin_session POST /admin/sign_in(.:format) devise/sessions#create
destroy_admin_session DELETE /admin/sign_out(.:format) devise/sessions#destroy
admin_password POST /admin/password(.:format) devise/passwords#create
new_admin_password GET /admin/password/new(.:format) devise/passwords#new
edit_admin_password GET /admin/password/edit(.:format) devise/passwords#edit
PUT /admin/password(.:format) devise/passwords#update
cancel_admin_registration GET /admin/cancel(.:format) devise/registrations#cancel
admin_registration POST /admin(.:format) devise/registrations#create
new_admin_registration GET /admin/sign_up(.:format) devise/registrations#new
edit_admin_registration GET /admin/edit(.:format) devise/registrations#edit
PUT /admin(.:format) devise/registrations#update
DELETE /admin(.:format) devise/registrations#destroy
login /admin/login(.:format) devise/sessions#new
login /admin(.:format) devise/sessions#new
admin_dashboard_index GET /admin/dashboard/index(.:format) admin/dashboard#index
Here is the content of routes.rb
devise_for :admin
devise_scope :admin do
match 'admin/login' => 'devise/sessions#new', :as => :login
match 'admin' => 'devise/sessions#new', :as => :login
get "admin/dashboard/index"
end
namespace :admin do
resources :images
end
And Admin model
class Admin < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
end
What is wrong here? I'm able to register or log-in, but I can't use helper methods.
Upvotes: 0
Views: 1569
Reputation: 114128
Since your model is Admin
you have to call
admin_signed_in?
and also
before_filter :authenticate_admin!
in your controller.
See https://github.com/plataformatec/devise/#configuring-multiple-models
Upvotes: 0
Reputation: 4956
try
admin_logged_in?
devise will use whatever the model is called
Upvotes: 1