Simple admin interface for Ruby on Rails applications.
Simple admin interface for Ruby on Rails applications.
Add this line to your application’s Gemfile:
gem 'adminable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install adminable
First things first. Add routes and create adminable/application_controller.rb
class using generator:
rails g adminable:install
# => create app/controllers/adminable/application_controller.rb
# => insert config/routes.rb
Assume you have model User
, then run:
rails g adminable:resource users
# => create app/controllers/adminable/users_controller.rb
For namespaced models, like Blog::Post
, use:
rails g adminable:resource blog/posts
# => create app/controllers/adminable/blog/posts_controller.rb
Change fields as you like inside fields
method array:
class Adminable::Blog::PostsController < Adminable::ResourcesController
def fields
[
Adminable::Fields::Integer.new(:id, form: false),
Adminable::Fields::String.new(:title),
Adminable::Fields::Text.new(:body),
Adminable::Fields::Float.new(:rating, form: false),
Adminable::Fields::Boolean.new(:published),
Adminable::Fields::BelongsTo.new(:user),
Adminable::Fields::HasMany.new(:blog_comments)
]
end
end
true
or false
, default: true
.
Shows field on index page.
true
or false
, default: true
.
Shows field on new/edit page.
true
or false
, default true
for integer
, boolean
, float
and decimal
fields, false
otherwise.
Adds text-align: center
for field value on index page.
true
or false
, default: false
.
Enables search for this field.
You can use generator to copy original partial to your application.
rails g adminable:partial [layout] [type] [resource]
layout
- index
or form
.type
- string
, text
etc. See Built-in Fields.resource
- Use controller name (e.g. users
) to replace partial only for single controller or leave blank to replace partials for all controllers.class Adminable::Blog::PostsController < Adminable::ResourcesController
def set_entry
entry = @resource.model.find_by(slug: params[:id])
super
end
end
The gem is available as open source under the terms of the MIT License.