LoginSignup
3
0

More than 1 year has passed since last update.

[rails×Heroku]ActionCable を本番環境でRadisを使って実装する方法

Posted at

railsプロジェクトを編集

conig/enviroment/production.rb
  # すべての送信元からのリクエストを許可
  config.action_cable.disable_request_forgery_protection = true
config/cable.yml
development:
  # adapter: async
  adapter: redis
  url: redis://localhost:6379

test:
  adapter: test
# 本番環境ではredisを使う、URLの部分を以下のように変更
production:
  adapter: redis
  # url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
  #  ↓ herokuのアドオンでradisを作成するとREDIS_URLという環境変数に自動的にURLを設定してくれる。
  url: <%=ENV['REDIS_URL']%>
  channel_prefix: room_api_production

Herokuでradisサーバーを作成する

heroku addons:create heroku-redis:プラン名でradisを新たに作成
プランは色々あるので、以下の本家サイトを参考にしてください。

ターミナル
heroku addons:create heroku-redis:hobby-dev

で、作成できたらradisのURLを確認する。

 heroku config:get REDIS_URL

スクリーンショット 2021-12-21 15.50.36.png

完了!

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