Rails: Installing The Super Awesome ActiveAdmin Backend
Monroe Mann
Published On: Nov 27, 2024
Editor’s Note: On all blog posts, we try to edit the writing as little as possible to preserve authenticity, personality, and writing style. We typically fix spelling errors, but minimally modify grammar and sentence structure (just enough to ensure readability).
Name: Monroe Mann Break Diving Level: Level 1 Number of Certified Dives: 15 From: United States In: United States
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'
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: [email protected]
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 => “[email protected]”, :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
Break Diving, Inc. is a tax-exempt 501(c)(3) charitable organization.
Read all about our amazing mission at www.BreakDiving.org
Join our free community at www.breakdiving.io
Remember to tell your friends about this www.BreakDiving.blog