David Fabreguette
David Fabreguette

Reputation: 982

General Routing to Active Admin - Rails 3.1

I'm currently trying to use Active Admin Gem with an existing Rails 3.1 app already configured with devise. This app uses a after_sign_in_path_for method declared in application controller.

I followed the steps explained there https://github.com/gregbell/active_admin, the thing is that when I try to access 0.0.0.0:3000/admin or localist:3000/admin I'm directly redirected to my home path.

Here's my route.rb file,

Fish::Application.routes.draw do

  devise_for :admin_users, ActiveAdmin::Devise.config

  ActiveAdmin.routes(self)




  get "goodnewslikes/create"

  get "goodnewslikes/destroy"

  resources :goodnews

  match "goodnews/share/:id" => "Goodnews#share", :as => "share_goodnews"

  match "churches/:id/changepicture" => "Churches#changepicture", :as => "change_picture_church"

  resources :churches



  match "home" => "Application#home", :as => "home"    

  match "currenthome" => "Application#currenthome", :as => "currenthome"

  match "globalsearch" => "Application#globalsearch", :as => "globalsearch"

  match "create_commentlike/:comment_id" => "Commentlikes#create", :as => "create_commentlike"

  resources :commentlikes, :only => [:destroy]

  match "create_postlike/:post_id" => "Postlikes#create", :as => "create_postlike"

  resources :postlikes, :only => [:destroy]


  match "create_goodnewslike/:goodnews_id" => "Goodnewslikes#create", :as => "create_goodnewslike"

  resources :goodnewslikes, :only => [:destroy]

  match "create_notifiations/:type/:user_id/:content_id" => "Notifications#create", :as => "create_notification"

  match "notifications/updateList" => "Notifications#updateList"

  resources :notifications, :except => [:edit, :create]

  resources :comments, :except => [:new]

  match "posts/:id/loadpic" => "Posts#loadpic", :as => "load_post_pic"

  match "comments/new/:post_id" => "Comments#new", :as => "new_comment"

  resources :friendships

  get "friendships/:id/accept" => "Friendships#accept", :as => "accept_friendship"

  get "friendships/:id/block" => "Friendships#block", :as => "block_friendship"


 get "users/searching" => "Users#searching", :as => "searching_users"
  resources :users, :only => [:index, :show] do
    match "profils/nouveau" => "Profils#new", :as => "new_profil"
    match "profils/:id/modifier" => "Profils#edit", :as => "edit_profil"
    resources :profils
  end


match "users/search" => "Users#search", :as => "search_users"



  match "posts_of/:user_id" => "Posts#index", :as => "posts_of"

  resources :posts





  devise_for :users, :path_prefix => "d"



  root :to => "Application#home"

  match "*path" => 'application#handle_404'
  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id(.:format)))'
end

Any idea ? I have no idea what's in "ActiveAdmin.routes(self)" so this is why I'm posting...

Thanks :-)

And here's my rake routes

    new_admin_user_session GET        /admin/login(.:format)                                    {:action=>"new", :controller=>"active_admin/devise/sessions"}
        admin_user_session POST       /admin/login(.:format)                                    {:action=>"create", :controller=>"active_admin/devise/sessions"}
destroy_admin_user_session DELETE|GET /admin/logout(.:format)                                   {:action=>"destroy", :controller=>"active_admin/devise/sessions"}
       admin_user_password POST       /admin/password(.:format)                                 {:action=>"create", :controller=>"active_admin/devise/passwords"}
   new_admin_user_password GET        /admin/password/new(.:format)                             {:action=>"new", :controller=>"active_admin/devise/passwords"}
  edit_admin_user_password GET        /admin/password/edit(.:format)                            {:action=>"edit", :controller=>"active_admin/devise/passwords"}
                           PUT        /admin/password(.:format)                                 {:action=>"update", :controller=>"active_admin/devise/passwords"}
           admin_dashboard            /admin(.:format)                                          {:action=>"index", :controller=>"admin/dashboard"}
         admin_admin_users GET        /admin/admin_users(.:format)                              {:action=>"index", :controller=>"admin/admin_users"}
                           POST       /admin/admin_users(.:format)                              {:action=>"create", :controller=>"admin/admin_users"}
      new_admin_admin_user GET        /admin/admin_users/new(.:format)                          {:action=>"new", :controller=>"admin/admin_users"}
     edit_admin_admin_user GET        /admin/admin_users/:id/edit(.:format)                     {:action=>"edit", :controller=>"admin/admin_users"}
          admin_admin_user GET        /admin/admin_users/:id(.:format)                          {:action=>"show", :controller=>"admin/admin_users"}
                           PUT        /admin/admin_users/:id(.:format)                          {:action=>"update", :controller=>"admin/admin_users"}
                           DELETE     /admin/admin_users/:id(.:format)                          {:action=>"destroy", :controller=>"admin/admin_users"}

Upvotes: 3

Views: 18636

Answers (3)

Piyush Chaudhary
Piyush Chaudhary

Reputation: 313

If you have devise configured already in your application for any other Models/Tables too. So you need to mention in the config file of active_admin that you don't need the sign-in of any other model before the login page of Admin.

You need to add below code if you do have only one devise models in your application named as User.

config.skip_before_action :authenticate_user!

You need to add below code if you do have two devise models in your application named as Student and Faculty.

config.skip_before_action :authenticate_student!, :authenticate_faculty!

Upvotes: 0

Azmat Rana
Azmat Rana

Reputation: 562

Because you have configured the devise. So you have to "except" the active admin path from the devise.

Your path localhost:3000/admin is checked by devise that are you logged in if no it will redirect you to your home page.

Add this line to your app->config->initializers->active_admin.rb file:

config.skip_before_filter :authenticate_user!

Upvotes: 2

DreadPirateShawn
DreadPirateShawn

Reputation: 8402

Copying the answer from the comments in order to remove this question from the "Unanswered" filter:

Actually the problem was that I set an after sign_in path for devise and I had to modify it in case we're logging in to admin panel. For that I just added a test and used the keyword "super" to keep the super after_sign_in_path method clean when loggin to admin_panel. This was suggested in this comment: https://github.com/gregbell/active_admin/issues/1133#issuecomment-4967768

~ answer per David Fabreguette

Upvotes: 1

Related Questions