Sunday, July 17, 2011

ActiveAdmin Tutorial

What is ActiveAdmin?
Active Admin is a Ruby on Rails plugin for generating administration sytle interfaces. The goals of this plugin are easy-to-use for non-techical users and fast for developers.



How To Use ActiveAdmin
Suppose we are create Blog web application.
$> rails new blog

Add the following to your Gemfile.
# Gemfile
gem 'activeadmin'

Run bundle install.
$> bundle install

Install ActiveAdmin.
$> rails generate active_admin:install

After installation is finished, it will create:
1. An configuration file on config/initializers/active_admin.rb
2. AdminUser model on app/models/admin_user.rb
3. An directory called app/admin to configure the admin interface of our resource.
4. Migration files.

Migrate your db and start the server.
$> rake db:migrate
$> rails server

Visit http://localhost:3000/admin and log in using:
  • Email: [email protected]
  • Password: password

Next, create Post model.
$> rails g model Post title:string content:text

Create admin interface for Post model. Because we use ActiveAdmin, we don't need to create controller for Post model. This generator will create file on app/admin/posts.rb.
$> rails generate active_admin:resource Post

This creates a file at app/admin/posts.rb for configuring the resource.
ActiveAdmin.register Post do
  index do
    column :title
    column :content
  end
end

Visit http://localhost:3000/admin/posts to see the result.

More information about ActiveAdmin:


11 comments:

  1. aussum.. i am sure this will help..!

    ReplyDelete
  2. What is on this post that isn't on the github page besides your google adwords?

    ReplyDelete
  3. hmm.. I couldn't install the activeadmin from your tutorial.
    when I've succeded install the activeadmin
    but when I tried this command "rails generate active admin:install"
    an error message come up, it said "Could not find generator active."

    ReplyDelete
    Replies
    1. me too..oops, it was 3 years ago..but i got the same error, does anyone have idea?

      Delete
  4. I missed something, what do you mean by "Configure admin interface index page for Post model." Where does that code go? Thanks!

    ReplyDelete
    Replies
    1. I mean write the code at app/admin/posts.rb file

      Delete
  5. Hey!
    How can i refresh second drop down based on first drop down, Ruby on Rails.I have Category and subcategory select dropdowns.I need to fetch the subcategories for the category which am selecting in the first dropdown.I am new to rails i dint get any solution in internet. Please help me.

    ReplyDelete
    Replies
    1. you can refresh subcategories via javascript.

      Delete
  6. This tutorial doesn't work for rails 4, just keep that in mind before starting.

    ReplyDelete

© Railsmine