Tuesday, August 6, 2013

Adding all the Admin functionality with the Active Admin gem and fixing problems with Active Admin

After toiling on admin screens for a few hours I learned a valuable lesson... there's a gem for that! The Active Admin gem gives you an entire framework for adding those screens. There's already great documentation and a Rails Cast on this.

For people like me, who didn't realize this until they were well into their app development but still want the functionality (trust me it looks sleek and easy to maintain) I recommend this blog which also points out how to implement the framework when you already have your authentication system up and running.

From there, at least at the time of this post, you'll need to make several fixes.

(1) In your routes.rb file, move your root to: "whatever#whatever' line to line 2. So that it's inside the app class but not the Active Admin class.

If you run rake routes you'll notice that Active Admin added another route path to dashboard#index.

(2) In your gem file, specify an older version of jquery-rails by inserting:
gem "jquery-rails", "2.3.0"
Then run
bundle update jquery-rails

Active Admin is dependent on something called jquery-ui which is not included in the more recent jquery-rails gem.

(3) In the Active Admin Initializer (config>initializers add:
config.logout_link_method = :delete
and  update:

config.logout_link_path = :destroy_admin_user_session_path
to whatever your user model is. So for me, it's:
config.logout_link_path = :destroy_user_session_path


(4) Notice that installing Active Admin created a migration to add Admin comments. Delete the migration file or, if you want them, rake db:migrate.

And that's all folks. Make sure to restart your server.

By the way, I'm using this over at https://github.com/eudaimonious/gating_app.git

Happy coding!