AdminInterface

A Rails admin interface generator for Rails 3.1+. Theme stolen from Redmine. Similar to web-app-theme.

More info

Generator to create some nifty admin scaffolds. It can work with MetaSearch and Kaminari. It also has admin authentication really well implemented.

Install

Rails 3

You should be using v1.2.0+ of the Gem. Add the following to your Gemfile.

gem 'admin_interface'

Usage / Example

Generate the initial framework (layout, etc.)

rails generate admin_interface:setup

This will:

  • Create an Admin::BaseController in app/controllers/admin/base_controller.rb

  • Create a layout in app/views/layouts/admin.html.erb

Change the app/controllers/admin/base_controller.rb to have a before filter only allowing admins to access it.

To view the admin page go to /admin (username: admin, password: admin).

Generate admin models and controllers

Create a scaffold for a model, for example:

rails generate admin_interface:scaffold post
rails generate admin_interface:scaffold post title:string body:text published:boolean
rails generate admin_interface:scaffold purchase order_id:integer amount:decimal

This will:

  • Create stuff similar to original Rails scaffold generator but for admin interface.

  • NOT create model since you probably have it already.

Pass the name of the model (in singular form), either CamelCased or under_scored, as the first argument, and an optional list of attribute pairs.

Attribute pairs are column_name:sql_type arguments specifying the model’s attributes. Timestamps are added by default, so you don’t have to specify them by hand as ‘created_at:datetime updated_at:datetime’.

Customize

You should customize your admin area so it can be more functional and nicely looking.

See it in action

Go to /admin and you can see everything in action.

Screenshot

Error messages

Add this to a initializer or in your environment.rb (see: railscasts.com/episodes/39-customize-field-error) This will make sure the admin errors will show in correct styling.

# Change the error from div to span
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
  "<span class='field_with_errors'>#{html_tag}</span>".html_safe
end

Note that this might affect the rest of your application. A different solution is welcome!

Kudos

Kudos, credits or whatever you like more go to:

  • Jean-Philippe Lang (creator of Redmine).

Copyright © 2012 Joost Hietbrink, released under the MIT license