はじめに
お疲れさまです。
おおくまです。
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'] %>
追加でデータベース名とユーザー名を設定する必要がある!
After
config/database.yml
production:
<<: *default
adapter: postgresql
encoding: unicode
database: #renderで設定したデータベース名
username: #renderで設定したユーザー名
url: <%= ENV['DATABASE_URL'] %>