Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to install and use Active Admin as your Admin Panel for Rails Application?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 491
    Comment on it

    As we know that these days every web application needs an admin panel which allows the owner or the manager of the web application to manage all the data and restrict the accessibility of certain things to certain users.

    For that there is a gem of Active admin which provides us with features to manage our data effectively.

     

    • First we need to install the gem in the gemfile as follows:
    gem 'activeadmin'

    and then run bundle install to install the gem.

     

    • Secondly we need to run the generator of active admin to generate all its files. 

    If you are using devise as your authentication mechanism then you need to write this code in your console

    $ rails g active_admin:install

     

    but if you do not want to use devise then fire the command like this

    $ rails g active_admin:install --skip-users

     

    and if you want to use any other existing user class, then provide that as an argument like this

    $ rails g active_admin:install User

     

    This will add these core files along with the other files

    app/admin/dashboard.rb
    app/assets/javascripts/active_admin.js.coffee
    app/assets/stylesheets/active_admin.scss
    config/initializers/active_admin.rb

     

    • Now we need to migrate and seed our database before starting the server like this
    $ rake db:migrate

     

    $ rake db:seed

    and then we need to start the server by firing rails s.

     

    • Now visit the URL localhost:3000/admin and login with these default credentials

    Username : admin@example.com

    Password : password

    And there you go. You are on board with active admin. Now you can change the default login credentials and put your own username and password.

     

    • Now at last register your models

    The models which you want to use with active admin you will have to run this command everytime you have to register a new model like this

    $ rails generate active_admin:resource MyModel

     

    When you are registering your model just make sure that you have already created all the crud operations of that model because these crud operations will be used to edit update and delete the data through your admin panel when needed.

    Along with this in the admin folder where our model gets registered we need to add our column names like this in the model file. Suppose we have a user.rb model file in admin folder so there we'll add our column names

    ActiveAdmin.register User do
    
      ....
      
      permit_params :first_name, :last_name, :email
    
      ....
    
    end

     Active Admin gives us some very nice features through which managing data becomes so easy. Some of those features are as follows:

    • It quickly creates good-looking administration interface.
    • We can view, add, update or delete data from any model and manage all the data easily and it gets updated everywhere.
    • It provides us with a special filter search form where we can search any data by putting the specific filters in the form.
    • We can import all the data to a csv,json or xml file easily and keep it with us

    So this is how you can install and use active admin.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: