Learning ActionCable

2024-06-12 rails postgresql

How to generate a simple ActionCable on rails app. If you built the app using postgresql, it can be used as the adapter(no need to install Redis and so on).

rails new myapp --database=postgresql
cd myapp
rails g channel notification
rails g scaffold room name occupied:boolean

You may need to update config/database.yml before creating database.

  username: username
  password: yourpassword

Initialize database.

rails db:create db:migrate

Modify the following files along with your purpose.


adapter: postgresql


stream_from "notification_channel"


# Add this where you want to notify the changes.
ActionCable.server.broadcast "notification_channel", {content: @room}


// Add the process when receiving messages like:

Next step: How to integrate this into minimal rails project..?