5
3

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.

RailsAPIモードをRailsに戻す方法

Last updated at Posted at 2020-12-17

RailsAPIを構築した時のコマンド

docker-compose run web rails new . --force --database=mysql --api --skip-bundle

これでRailsAPIを生成しました。

通常のRails戻したい。

同じディレクトリで、今度は --apiを引いて、

docker-compose run web rails new . --force --database=mysql --skip-bundle

RailsAPI時に作成したファイルはそのまま残っています。

application_controller.rb
- class ApplicationController < ActionController::API
+ class ApplicationController < ActionController::Base
application.rb
- config.api_only = false

あとはdockerで必要なコマンドを実行するだけです。

docker-compose build
docker-compose run web rails db:create
docker-compose up -d

補足
https://shakacode.gitbooks.io/react-on-rails/content/docs/additional-reading/convert-rails-5-api-only-app.html
https://stackoverflow.com/questions/36669981/how-do-you-convert-a-rails-5-api-app-to-a-rails-app-that-can-act-as-both-api-and

5
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?