8
6

【Rails】renderでのデプロイ時のミスまとめ

Last updated at Posted at 2023-09-29

はじめに

お疲れさまです。
おおくまです。

Railsで実装したアプリをrenderでデプロイした際になかなか上手くいきませんでした。
ほとんどがタイポでした。笑
備忘録として残したいと思います。

環境

Ruby 3.2.2
Rails 7.0.8
Webアプリケーションサーバ render
データベース PostgreSQL

注意点

私はプログラミング学習中で、初学者です。
内容に誤りがある場合があります。
コメント等で教えていただけると幸甚です。

①ホストの許可

Before

config/environments/production.rb
Rails.application.configure do
  config.hosts << 'https://********.onrender.com'
end

After

config/environments/production.rb
Rails.application.configure do
  config.hosts << '********.onrender.com'
end

「https://」が余計だったみたいです!

②DATABASE_URL

renderでデータベース作成時に「Internal Database URL」と「External Database URL」の両方が作成される。
当初は、「Internal Database URL」を「DATABASE_URL」として環境変数に設定していたが、「External Database URL」で設定し直すことで上手くいった。

③PostgreSQLの設定

Before

config/database.yml
production:
  <<: *default
  adapter: postgresql
  encoding: unicode
  url: <%= ENV['DATABASE_URL'] %>

追加でデータベース名とユーザー名を設定する必要がある!


renderでデータベースを作成する際の画面
スクリーンショット 2023-09-29 11.46.20(2).jpeg


After

config/database.yml
production:
  <<: *default
  adapter: postgresql
  encoding: unicode
  database: #renderで設定したデータベース名
  username: #renderで設定したユーザー名
  url: <%= ENV['DATABASE_URL'] %>
8
6
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
8
6