Rails: Installing The Super Awesome ActiveAdmin Backend

by Dr. Monroe Mann, PhD, Esq, MBA, LLM, ME
Founder & Exec. Dir., Break Diving, Inc.

If you’re a rails user, awesome news: there’s an amazing gem that takes less than 5 minutes to install, and voila, you’ve got a beautiful admin backend to handle all of your users.  These instructions assume that you are also using devise for user authentication.

1. Add this to the gemfile:

gem 'activeadmin'

Remember to run: bundle install.

2. Type into your ruby command line:

rails g active_admin:install

Remember, this assumes that you have already created a User model with devise

3. Migrate and seed your database.  First, check the migration file called “add_devise_to_admin_users” and make sure that the command is create_table and NOT update_table or anything else.  Then:

rake db:migrate
rake db:seed

4. Restart your rails server and visit your localhost server followed by /admin (i.e. localhost:3000/admin) and type the following:

User: admin@example.com
Password: password

5.  Congrats!  You now have an admin backend!  Click on the ‘Users’ tab and you’ll find some cool information.

6. Next: to set up other models within your admin backend, so you have a full view of what’s happening with your users inside the app, run this code, substituting MyModel with the name of the model you want added to the admin backend.  Repeat for each model:

rails generate active_admin:resource MyModel

7. Finally, be sure to create a new admin user once you are in there.  You will see the tab called ‘admin users’.  Create the new one and make sure it works.  Then delete the old one.  Be sure to keep note of your username and password, obviously.

NOTE: this gem may install a different version of jQuery, which may affect your app if you are using jQuery.  You may have to override the jquery version that ActiveAdmin installs if you find that you are having difficulty.  What my team found that worked on our app is this:

  • Rename the file active_admin.js.coffee to just active_admin.js
  • Add this code:
    /* Active Admin JS */
    /* copied from ‘app/assets/javascripts/base.js in active_admin source code */
    $(function(){
    $(“.datepicker”).datepicker({dateFormat: ‘yy-mm-dd’});$(“.clear_filters_btn”).click(function(){
    window.location.search = “”;
    return false;
    });
    });
    /* END COPY */
  • In active_admin.rb add at top:current_javascripts = config.javascripts.clone
    config.clear_javascripts!
    config.register_javascript ‘application.js’
    current_javascripts.each{|j| config.register_javascript j}

8. Don’t forget to launch to heroku as follows:

  • heroku run rake db:migrate
  • heroku run rake db:seed
  • heroku run rails c
  • admin = AdminUser.new({:email => “youremailhere@aol.com”, :id => “1”, :password => “your_password_here”, :password_confirmation => “your_password_here” })
  • admin.save
  • heroku restart

 

For more information:
https://activeadmin.info/0-installation.html
https://stackoverflow.com/questions/8788304/activeadmin-stops-my-jquery-working
https://github.com/activeadmin/activeadmin/pull/468

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s