Skip to content

Instantly share code, notes, and snippets.

@jennli
Created March 17, 2016 21:59
Show Gist options
  • Save jennli/a2c5d070264feac590e2 to your computer and use it in GitHub Desktop.
Save jennli/a2c5d070264feac590e2 to your computer and use it in GitHub Desktop.

Active admin panel

gem 'activeadmin', github: "activeadmin/activeadmin"
gem "devise"
rails g active_admin:install

$ rails g active_admin:install
Running via Spring preloader in process 64067
      invoke  devise
    generate    devise:install
      create    config/initializers/devise.rb
      create    config/locales/devise.en.yml
  ===============================================================================

Some setup you must do manually if you haven't yet:

  1. Ensure you have defined default url options in your environments files. Here
     is an example of default_url_options appropriate for a development environment
     in config/environments/development.rb:

       config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

     In production, :host should be set to the actual host of your application.

  2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:

       root to: "home#index"

  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:

       <p class="notice"><%= notice %></p>
       <p class="alert"><%= alert %></p>

  4. If you are deploying on Heroku with Rails 3.2 only, you may want to set:

       config.assets.initialize_on_precompile = false

     On config/application.rb forcing your application to not access the DB
     or load models when precompiling your assets.

  5. You can copy Devise views (for customization) to your app by running:

       rails g devise:views

===============================================================================
      invoke    active_record
      create      db/migrate/20160317214236_devise_create_admin_users.rb
      create      app/models/admin_user.rb
      invoke      rspec
      create        spec/models/admin_user_spec.rb
      invoke        factory_girl
      create          spec/factories/admin_users.rb
      insert      app/models/admin_user.rb
       route    devise_for :admin_users
        gsub    app/models/admin_user.rb
        gsub    config/routes.rb
      append    db/seeds.rb
      create  config/initializers/active_admin.rb
      create  app/admin
      create  app/admin/dashboard.rb
      create  app/admin/admin_user.rb
      insert  config/routes.rb
    generate  active_admin:assets
Running via Spring preloader in process 64071
      create  app/assets/javascripts/active_admin.js.coffee
      create  app/assets/stylesheets/active_admin.scss
      create  db/migrate/20160317214240_create_active_admin_comments.rb
have fun coding Jenn Li: jan-2016-awesome-answers (jenli_awesome_answers)

generated the following in the seed:

AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password')
  • run db migrate, seed

  • use the following command to generate admin resource for models like user, question, etc

bin/rails g active_admin:resource user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment