HyperAdmin is an admin interface solution for Ruby on Rails. It works pretty much as a mountable engine, except it always mounts under /admin. This is currently not configurable.
Simply put the gem in your Rails application's Gemfile:
Then, install the bundle as usual:
$ bundle install
Finally, mount HyperAdmin into your application. Put this in your config/routes.rb file:
HyperAdmin.routes self mount HyperAdmin::Engine, at: '/admin'
As mentioned above, you must mount it under /admin for the time being. In a later version, this will be configurable.
To register models that should be accessible through the admin, all you need to do is register them with a single line of code. Do this in any Ruby file(s) you want under app/admin/, such as app/admin/article.rb or app/admin/person.rb. When the application boots, HyperAdmin will check each file under the app/admin/. To register a resource:
With this in place, you can now visit /admin/articles in your application and start managing your articles.
When registering resources, it is also possible to customize what fields should
show up where and (to some degree) how they should be displayed. For instance,
we might want to only show the ID, title and publication date of an article in
the index view. For that, we would pass in a block to
register and specify
which columns to display on the index view, like this:
HyperAdmin.register Article do index do column :id column :title column :published_at end end
Note that the order matters here, so this could also be used to force an order
of attributes to be displayed. In the example above, HyperAdmin would know the
types of the attributes because of how it is registered in the database.
However, some types cannot be determined from the database alone. URL fields and
e-mail fields, for instance, are stored as text, so they will be treated as text
by default. It is possible to tell HyperAdmin what type of field you're
specifying by using the
HyperAdmin.register Article do index do column :id column :title column :published_at column :author_email, type: :email end end
The “email” type will create a “mailto”-style link in the index and show
views, and an
<input type="email"> in the form. Likewise, the “url” type will
create a regular link in index/show and an
<input type="url"> in forms.
Lastly, it is also possible to customize the labeling of the attributes in each
view using the
HyperAdmin.register Article do index do column :id column :title column :published_at, human: "Publication date" column :author_email, type: :email end end
Note that if
human is not specified, HyperAdmin will fetch the attribute name
from the currently active locale, which is recommended most of the time.
is available for special cases where you want a label other than the localized
name of the attribute.
Customizing the show and form pages work the same way as the index pages, but
field methods instead, respectively. A fully customized
resource registration might look something like this:
HyperAdmin.register Article do index do column :id column :title column :published_at, human: "Publication date" end show do row :id, human: "Article ID" row :title row :body row :published_at, human: "Publication date" column :author_email, type: :email end form do field :title field :body field :published_at field :author_email, type: :email end end
- Fork it
- Check out the develop branch (
git checkout develop)
- Create your feature branch (
git checkout -b feature/my-new-feature)
- Commit your changes (
git commit -am 'Add my new feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request
Hyper made this. We're a digital communications agency with a passion for good code, and if you're using HyperAdmin we probably want to hire you.
HyperAdmin is available under the MIT license. See LICENSE.md for more details.