2

I just installed ActiveAdmin and everything was going well:

The gem is installed and I ran the install command. I was able to go to localhost:3000/admin and signed in with the admin@example and 'password' credentials as laid out in the documentation.

However, when I click on "Login", I get the following:

No route matches {:action=>"show", :controller=>"users", :id=>nil}

My routes.rb file:

devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)

devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}

resources :offers

resources :users do
collection do
  get :currentoffers
end

My users_controller.rb:

def index
end

def show
    @user = User.find(params[:id])
end

def currentoffers
    #calls the currentoffers.js.erb file
    respond_to do |format|
        format.html
        format.js
    end
end

What I get when I run rake routes:

admin_root            /admin(.:format)                          admin/dashboard#index
batch_action_admin_admin_users POST       /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
         admin_admin_users GET        /admin/admin_users(.:format)              admin/admin_users#index
                           POST       /admin/admin_users(.:format)              admin/admin_users#create
      new_admin_admin_user GET        /admin/admin_users/new(.:format)          admin/admin_users#new
     edit_admin_admin_user GET        /admin/admin_users/:id/edit(.:format)     admin/admin_users#edit
          admin_admin_user GET        /admin/admin_users/:id(.:format)          admin/admin_users#show
                           PUT        /admin/admin_users/:id(.:format)          admin/admin_users#update
                           DELETE     /admin/admin_users/:id(.:format)          admin/admin_users#destroy
           admin_dashboard            /admin/dashboard(.:format)                admin/dashboard#index
 batch_action_admin_comments POST       /admin/comments/batch_action(.:format)    admin/comments#batch_action
            admin_comments GET        /admin/comments(.:format)                 admin/comments#index
                           POST       /admin/comments(.:format)                 admin/comments#create
             admin_comment GET        /admin/comments/:id(.:format)             admin/comments#show
    new_admin_user_session GET        /admin/login(.:format)                    active_admin/devise/sessions#new
        admin_user_session POST       /admin/login(.:format)                    active_admin/devise/sessions#create
destroy_admin_user_session DELETE|GET /admin/logout(.:format)                   active_admin/devise/sessions#destroy
       admin_user_password POST       /admin/password(.:format)                 active_admin/devise/passwords#create
   new_admin_user_password GET        /admin/password/new(.:format)             active_admin/devise/passwords#new
  edit_admin_user_password GET        /admin/password/edit(.:format)            active_admin/devise/passwords#edit
                           PUT        /admin/password(.:format)                 active_admin/devise/passwords#update
          new_user_session GET        /login(.:format)                          devise/sessions#new
              user_session POST       /login(.:format)                          devise/sessions#create
      destroy_user_session DELETE     /logout(.:format)                         devise/sessions#destroy
   user_omniauth_authorize            /auth/:provider(.:format)                 devise/omniauth_callbacks#passthru {:provider=>/facebook/}
    user_omniauth_callback            /auth/:action/callback(.:format)          devise/omniauth_callbacks#(?-mix:facebook)
             user_password POST       /password(.:format)                       devise/passwords#create
         new_user_password GET        /password/new(.:format)                   devise/passwords#new
        edit_user_password GET        /password/edit(.:format)                  devise/passwords#edit
                           PUT        /password(.:format)                       devise/passwords#update
  cancel_user_registration GET        /cancel(.:format)                         devise/registrations#cancel
         user_registration POST       /                                         devise/registrations#create
     new_user_registration GET        /sign_up(.:format)                        devise/registrations#new
    edit_user_registration GET        /edit(.:format)                           devise/registrations#edit
                           PUT        /                                         devise/registrations#update
                           DELETE     /                                         devise/registrations#destroy

Would anyone know why I am getting this error? Is is that including the users resource in the routes.rb file is interfering with ActiveAdmin?

---Update:

# Application_controller.rb:

class ApplicationController < ActionController::Base
    protect_from_forgery

def after_sign_in_path_for(resource)
    user_path(@user)
end

end
7
  • did you click Log In on site or in admin section? where did it redirect to? Commented Apr 1, 2013 at 5:58
  • I clicked Log In in the admin section, localhost3000/admin. I didn't get redirected anywhere - I just was shown a blank page with the error above. Commented Apr 1, 2013 at 20:15
  • ok, what's in the log? Commented Apr 2, 2013 at 5:51
  • I am getting: Processing by ActiveAdmin::Devise::SessionsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"pU6hyEvFw8i4W5EjfXxQKcFdoGmWtjyQU//cmSHwfp8=", "admin_user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Login"} AdminUser Load (1.3ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."email" = '[email protected]' LIMIT 1 Commented Apr 3, 2013 at 1:32
  • ActionController::RoutingError (No route matches {:action=>"show", :controller=>"users", :id=>nil}): app/controllers/application_controller.rb:5:in after_sign_in_path_for' app/controllers/devise/sessions_controller.rb:18:in create' Commented Apr 3, 2013 at 1:33

3 Answers 3

4

try this,

def after_sign_in_path_for(resource)
  user_path(resource)
end

problem is in,

 user_path(@user)

where @user is not defined, hence nil.

Sign up to request clarification or add additional context in comments.

3 Comments

Strage - It works now, but when I log in with the admin credentials, instead of taking me to the admin dashboard, it takes me to /users/1 - must be a simple routing error, any idea on how to route correctly to the activeadmin side?
Not as that strange. It is because you are overriding the devise url path after. You can replace user_path(resource) by admin_dashboard_path in after_sign_in_path_for(resource) or whatever you want.
or you can check if it is admin user, by resource.instance_of?(AdminUser) and redirect conditionally.
3

move this line

ActiveAdmin.routes(self)

above this line

devise_for :admin_users, ActiveAdmin::Devise.config

Comments

0

moving

ActiveAdmin.routes(self)

before

 devise_for :admin_users, ActiveAdmin::Devise.config

causes an error because of ActiveAdmin bug of extra '/' route being generated, the bug was fixed in ActiveAdmin 0.6.1 upgrading ActiveAdmin will allow the fix that solved the problem for us.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.