AdminInterface

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

More info

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

Install

Add following to your Gemfile

group :development, :test do
  # Generators
  gem 'admin_interface'
end

Or install as plugin from Github.

rails plugin install git://github.com/joost/admin_interface.git

Usage / Example

Generate the initial framework (layout, etc.)

rails generate admin_interface

This will:

  • But some images (stolen from Redmine) into public/images/admin/

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

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

  • Add some jQuery javascripts and CSS

Next, add following routes to config/routes.rb.

namespace :admin do
  root :to => 'base#index'
  # Add the following after you've used the admin_scaffold generator
  resources :model do
    delete 'delete_all', :on => :collection
  end
end

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

Generate admin models and controllers

Create a scaffold for a model, for example:

rails generate admin_scaffold post
rails generate admin_scaffold post title:string body:text published:boolean
rails generate admin_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’.

See it in action

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

Error messages

Add this to 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='fieldWithErrors'>#{html_tag}</span>"
end

Kudos

Kudos, credits or whatever you like more go to:

  • Jean-Philippe Lang (creator of Redmine).

Copyright © 2010 Joost Hietbrink, released under the MIT license