LoginSignup
13
9

More than 5 years have passed since last update.

Rails5へのActiveAdminの導入

Last updated at Posted at 2016-08-27

基本的にActiveAdminのreadme読めばいいだけの話ですが作業メモがてら

1.Gemfileを編集

依存関係にあるのでdevise未導入の場合は一緒に導入

Gemfile
# framework for creating administration style interfaces
gem 'activeadmin', github: 'activeadmin'
gem 'inherited_resources', github: 'activeadmin/inherited_resources'
gem 'devise' # if you need

2. bundle install

3. インストーラを実行

bundle exec rails g active_admin:install 

いつもの設定事項リストなので割愛

  ===============================================================================

Some setup you must do manually if you haven't yet:

  1. Ensure you have defined default url options in your environments files. Here
     is an example of default_url_options appropriate for a development environment
     in config/environments/development.rb:

       config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

     In production, :host should be set to the actual host of your application.

  2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:

       root to: "home#index"

  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:

       <p class="notice"><%= notice %></p>
       <p class="alert"><%= alert %></p>

  4. You can copy Devise views (for customization) to your app by running:

       rails g devise:views

===============================================================================

4. DB migration

AdminUserモデルのmigrationファイルが生成され、seed.rbに初期ユーザのseedが追記されているので反映
この際、初期管理者ユーザのmail, P/W は以下を編集しておけば変更できる

db/seed.rb
AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password')

migrationを実行

bundle exec rails db:migrate
bundle exec rails db:seed

5. 動作確認

bundle exec rails s

http://localhost:3000/admin へアクセスして、初期管理者ユーザのmail, P/Wでログインできれば成功

13
9
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
13
9