To create a custom rails_admin dashboard, first create a new file here:
And in your rails_config/initializers/rails_admin.rb initializer file, be sure to include the above file:
RailsAdmin.config do |config| require Rails.root.join('lib', 'rails_admin.rb') end
Within this new file, do the following:
module RailsAdmin module Config module Actions class Dashboard < RailsAdmin::Config::Actions::Base RailsAdmin::Config::Actions.register(self) register_instance_option :root? do true end register_instance_option :breadcrumb_parent do nil end register_instance_option :controller do proc do #You can specify instance variables @custom_stats = "grab your stats here." #You can access submitted params (just submit your form to the dashboard). if params[:xyz] @do_something = "here" end #You can specify flash messages flash.now[:danger] = "Some type of danger message here." #After you're done processing everything, render the new dashboard render @action.template_name, status: 200 end end register_instance_option :route_fragment do '' end register_instance_option :link_icon do 'icon-home' end register_instance_option :statistics? do true end end end end end
Now that we have our instance variables, we can customize the actual dashboard HTML by creating the associated file and doing whatever we like.
This will completely replace the body of the current dashboard statistics page. If you want to maintain some of that functionality, you can always recreate it from the dashboard.html.haml file found within the rails_admin repository.
This is great if you're unsatisfied with the out-of-the-box statistics and want to produce something more robust.
Thanks Anthony! Your article was exactly what I needed. Peace!
Thanks man, super article, It helped lot!. Can give some tips on customizing navigation(side bar), I want to customize it like active admin, there we can add menu submenu in title bar.
Thanks Anthony! help me a lot !