Rails 3.1 admin
JavaScript CSS Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Flexible Admin

Reason for being

Flexible Admin is a Rails 3.1 Admin tool to generate an attractive data admin to handle login, data CRUD, search and sort while leaving an easy way to customize the particular needs of an app’s custom admin functions.

I have found myself loving other admins for Rails, but many projects need enough admin customization that the value of a engines/magic was offset by the difficulty of customizing.

Depends On

  1. Rails 3.1+

Basically needs

  1. SQL database / ActiveRecord. Most of the cool stuff involves intuiting your admin needs from your sql column names/typues

Customized for

  1. Paperclip file attachments

Distinctions from other Rails admin gems

Flexible admin generates controller and view files for every model that you are managing, then invites you to get your hands dirty for the customizations of the admin.

It keeps the amount of generated code down by leveraging these gems/libraries to do the heavy lifting

  1. Devise for login
  2. Bootstrap for style
  3. inherited_resources for rest controllers
  4. Database Tables (js) for table searching and sorting

Shortcomings from other Rails admins gems

  1. Does not natively handle huge amounts of records for viewing. You would need to implement handling a large number of records for searching/sorting yourself. (Because Flexible Admin renders every record of a certain model, and then Datatables js presents just 50 at a time that is paginated/filterable/sortable with javascript)
  2. Because this is a generator, not an engine, the resource generator might become less effective (=breaks more) as you admin gets more and more customized. This is because its replacing/inserting code that may have modified.

Getting Started

In your Gemfile

gem 'flexible_admin'

run bundle install

run rails generate flexible_admin:install

run rake db:migrate to create admin_users tables

Adding models

run rails generate flexible_admin Post to generate a admin/posts controller, /admin/posts route, and add Posts to the admin navigation

Adding devise (authentication)

run rails generate flexible_admin:devise to generate devise, an admin_user, and require login for the admin.

Adding WYSIWYG editor

run rails generate flexible_admin:ckeditor to install and generate ckeditor. That will turn all fields named Body and Description into a text editor. It also supports pictures and file attachments in the body and configures ckeditor to use amazon_s3 to store the pic/uploads.

The pics/attachment uploads for ckeditor depend on paperclip for file uploads. If you use another file attachment handler, install ckeditor yourself from the gem: https://github.com/galetahub/ckeditor

Editing views and controllers

Edit views directly in the app/views/admin, app/views/layouts/admin and app/views/controllers/admin


You can (and should) edit the /admin view at app/views/admin/index.html. It starts out blank.


Every view file does or can have a content_for :sidebar block where you can content for the sidebar


Gem tests

Flexible Admin as a gem is tested with rspec. The specs cover that the generator generates the right files. It does not test that you can actually admin in anything after the generator runs.

Tests needed

If possible, my dream tests would run the admin generator on a dummy_app, then step into the dummy app and run a new test suite on how that app behaves after the generator has been run. If anyone knows how to do that get in touch through github, email or the Issues section.

Working with the tests gotchas

The generator specs really on a dummy Rails app in the spec/dummy folder. That dummy app has some models, a schema, and a db/test.sqlite3 that matter for the tests. You might have to dig into those if you are having problems modding the specs. One of the generators reads the models and the database columns to generate the admin forms, and so the dummy app has those files to test off it.


This project rocks and uses MIT-LICENSE.