The ActiveAdmin gem provides us with a entirely separate administrative sub-site. It's amazingly full-featured out of the box, and also is extremely customizable.
In your Gemfile, include
gem 'activeadmin', '~> 1.0.0.pre4'
gem 'inherited_resources', github: 'activeadmin/inherited_resources'If you don't already have the Devise gem in your application, you'll need to add that too:
gem 'activeadmin', '~> 1.0.0.pre4'
gem 'inherited_resources', github: 'activeadmin/inherited_resources'
gem 'devise'and then bundle install.
From the command line:
rails g active_admin:install
rake db:migrate
rake db:seedNote: If you are using Devise's
before_action :authenticate_user!filter in yourApplicationController, then add the following line toconfig/active_admin.rb:
config.skip_before_filter :authenticate_user!
Restart your rails server.
Visit http://localhost:3000/admin and log in as the default user:
- User:
[email protected] - Password:
password
Voila! You're on your brand new Active Admin dashboard. You should change the email and password of this admin user immediately.
Note: if you get an error relating to ExecJS, try deleting the
app/assets/javascripts/active_admin.js.coffeefile.
To register existing models with Active Admin:
rails generate active_admin:resource neighborhood
rails generate active_admin:resource venue
rails generate active_admin:resource cuisine
rails generate active_admin:resource dish
rails generate active_admin:resource user
rails generate active_admin:resource favoriteRefresh your admin view and you should now have links in your navbar to manage each of these resources.
In the app/admin folder, you will find a file for each model you registered. Within it, uncomment the line that begins with permit_params and customize the list to include any columns that you want to allow to be modified through the admin interface:
# app/admin/venue.rb
permit_params :name, :address, :neighborhood_idThat's it! You now have a fully-functional admin interface that you can use to go in and CRUD data as necessary, without having to complicate your actual controllers and views with a bunch of conditionals. You can now focus entirely on your users there.
If you find that ActiveAdmin's CSS styles are polluting your own, in app/assets/stylesheets/application.css, delete the line
*= require_tree .