Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant DashboardController for localhost: when accesing site area accept admin side

hello i have issue with "uninitialized constant DashboardController" when i open my site with localhost:3000. it shows me above error. its is not allowing me to enter user side.

i have lots of models for admin as well users so i need solution for this error.

y it so.... and i have define root :to => 'home/index' as my root file so whenever i write localhost in my browser it fails to load.

i have installed devise for user and active-admin for admin.

// for devise user session
controller :sessions do 
  get 'login' => :new
  post 'login' => :create
  delete 'logout' => :destroy
end

root :to => 'home#activity_list' //for localroot


New Question and its Answer :


If you are getting this error then jus do this.

Processing by Admin::DashboardController#index as HTML Completed 401 Unauthorized in 1ms

This arises when you try to open localhost:3000/admin and it redirects to localhost:3000/usres/sign_in

then you can add those three lines, so copy these three lines and paste at the bottom of the file(after ActiveAdmin.setup do |config| .... end) in config/initializers/active_admin.rb.

 ActiveAdmin::BaseController.class_eval do
   skip_before_filter :authenticate_user!
 end     

Actually i have

before_action :authenticate_user!

in my application_controller.

Just open ActiveAdmin::BaseController and put the skip_before_filter in there.

like image 478
SSR Avatar asked Apr 17 '13 16:04

SSR


1 Answers

In routes.rb:

  root :to => 'frontpage#index' # MUST be before ActiveAdmin (as SSR said)

  devise_scope :users do # Must also be before ActiveAdmin
    root :to => "frontpage#index"
  end

  namespace :admin do
    root to: 'users#index' # if you want to be on user by default on the admin 
    #resources :dashboard <= Remove this line if you have it
  end

  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  devise_for :users, :controllers => {:omniauth_callbacks => 'omniauth_callbacks'}
  ActiveAdmin.routes(self)

If you have the error uninitialized constant DashboardController, just remove everything in app/helpers/admin/


Another method is to just add a is_admincolumn to your user table.

Then, add this in initializers/active_admin.rb:

config.authentication_method = :authenticate_admin_user!
config.current_user_method = :current_admin_user

And this in application_controller.rb

def authenticate_admin_user!
  if !current_user.is_admin
    flash[:error] = "You must be admin to access this page."
    redirect_to root_path
    return
  end

end

This way, you don't need the admin_user table. Just change is_admin from 0 to 1 for a user to become admin.

like image 70
Benjamin Crouzier Avatar answered Nov 15 '22 08:11

Benjamin Crouzier