32
34

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 5 years have passed since last update.

RailsAdminを導入してみた

Last updated at Posted at 2012-08-02

Rails3 で管理画面を作成するなら RailsAdmin で決まりかもに沿ってやってみたけど、ちょこちょこ躓いたのでメモ。

deviseは2.1.2、rails_adminは0.0.5。

gem 'devise'
gem 'rails_admin'

ここでは管理者のモデルをAdminとする。まずはdeviseでこれを作る。

$ bundle install
$ rails g devise Admin
$ vim app/models/admin.rb
-  devise :database_authenticatable, :registerable,
-         :recoverable, :rememberable, :trackable, :validatable
+#  devise :database_authenticatable, :registerable,
+#         :recoverable, :rememberable, :trackable, :validatable
$ vim config/routes.rb
-  devise_for :admins
+#  devise_for :admins
$ rake db:migrate

これでadminsテーブルができた。
続けてrails_adminを導入する。

$ rails g rails_admin:install
$ vim app/models/admin.rb
-#  devise :database_authenticatable, :registerable,
-#         :recoverable, :rememberable, :trackable, :validatable
+  devise :database_authenticatable, :registerable,
+         :recoverable, :rememberable, :trackable, :validatable

マウントする前にdeviceに登録するようにルーティングを調整。

$ vim config/routes.rb
+  devise_for :admins
   mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
-
-#  devise_for :admins
$ rake db:migrate
$ open http://127.0.0.1:3000/admins/sign_up

ユーザの登録が終わったら:registerableを外す

$ vim app/models/admin.rb
-  devise :database_authenticatable, :registerable,
+  devise :database_authenticatable,
32
34
1

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
32
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?