5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

管理画面生成gem Administrate の紹介と導入

Posted at

Railsで管理画面を作るとき、どうしてますでしょうか。
ちゃんと作りたいなら自作のがよいと思いますが、個人開発など、そこまで工数割けないよ!という時のために、
管理画面生成gem Administrate を紹介したいと思います。

Administrate とは

管理画面を自動生成するRailsライブラリ。
技術者以外のユーザーに、アプリケーション内の任意のレコードの作成、編集、検索、削除をできるクリーンなインターフェースを提供します。(公式より

文面を見ても分からないと思うので、公式のデモを触るのが早いです。

公式サイト(英語): https://administrate-prototype.herokuapp.com/
公式デモ: https://administrate-prototype.herokuapp.com/admin
公式Github (thoughtbot/administrate): https://github.com/thoughtbot/administrate

※注意

version 1.0 以前なので、APIに大きな変更が加えられる可能性があります。
updateする前にリリースノートを確認した方がよさそうです。

Administrate is still pre-1.0, and there may be occasional breaking changes to the API.

image.png

導入

Gemfileに追記

# Gemfile
gem "administrate"

bundle install 後、インストラーを実行する

# デフォルト設定での install (デフォルトのnamespace: admin)
$ rails generate administrate:install

# 任意のnamespaceを使いたいとき (namespace: supervisor)
$ rails generate administrate:install --namespace=supervisor

config/routes.rb/adminのルートが追加され、app/controllers/admin/application_controller.rbが生成されます。
また、ActiveRecordリソースごとに Dashboard と Controller が生成されます。

  • app/controllers/admin/foos_controller.rb
  • app/dashboards/foo_dashboard.rb

※namespaceを指定した際は、ルートもディレクトリ名も変わります

# --namespace=supervisor の場合
http://localhost:3000/supervisor
app/controllers/supervisor/application_controller.rb

終わりに

これで導入が完了し、一通りの機能(作成、編集、検索、削除)が使えるようになりました。
Administrateは、使いやすいように色々とカスタマイズ出来るので、次回いくつか紹介したいと思います。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?