Ultra simple DRY admin UI making use of make_resourceful and formtastic.
Ruby HTML JavaScript CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config/initializers
lib
tasks
.gitignore
Gemfile
Gemfile.lock
README.md
Rakefile
easy_admin_ui.gemspec

README.md

easy_admin_ui

A very simple admin UI. If you need something more fancy look try https://github.com/sferik/rails_admin.

Docs are incomplete.

Requirements

  • Ruby >= 2.0
  • Rails 4.0 or later. (0.6.x works with 3.2.x)
  • formtastic 2.2.1 or higher (specify it in your Gemfile if needed)
  • kaminari
  • jQuery

Note

Some things are currently hardwired as this is very much my own hacky admin thing. For instance it assumes you have your controllers below admin/. I.e. admin_users_path.

Installation

$ gem install easy_admin_ui

In your controller:

class Admin::UsersController < ActionController::Base
  easy_admin :per_page => 50,
    :order => 'created_at',
    :page_title => 'Users',
    :columns => ['Login', ['Email', 'my_nowrap_class'], 'Name', 'Created'],
    :show_actions => true,
    :skip_new => true,
    :include => '
       after :create do
         # Stuff you want to do after create.
       end'
end

The model is infered by the make_resourceful plugin which is why we don't need to specify it here. However, the object(s) returned will be named @item or @items (for :index).

Then you need a partial below users/ named '_user.html.erb':

<%=
  table_row(:id => "tr_user_#{user.id}", :class => "#{cyc = cycle("even", "odd")}",
    :cells => [
      user.login,
      [user.email, 'my_nowrap_class'],
      date_hm(user.created_at),
    ],
    :actions => [
      admin_edit_link(user),
      admin_delete_link_with_confirmation(user)
    ])
-%>

For deeper nested resources simply use:

admin_show_link([user, article])
admin_delete_link_with_confirmation([user, comment])

This also works for forms but you need to set

To add a class to your table cells just pass an array as done with the user.email field in the above example.

You need to provide the _form.html.erb partials yourself.

You can always override the default templates by providing templates yourself.

Optional Partials

Sometimes you'll need extra stuff on your page such as a form filter for the records. You can use the following optional partials to add functionality.

Index page only:

_index_after_title.html.erb
_index_after_table.html.erb

New/edit pages:

_modify_after_title.html.erb
_modify_after_form.html.erb

If these exist the more specific partials below will not be rendered.

Edit page only:

_edit_after_title.html.erb
_edit_after_form.html.erb

New page only:

_new_after_title.html.erb
_new_after_form.html.erb

Will be included on all actions no matter if other partials were present or not:

_after_title.html.erb
_after.html.erb