Realtime Partial Update App
This is a sample of how to use ActionCable & Stimulus to update partials in Rails 6.
- config/cable.yml - I setup the local adaptor to be
redisso ActionCable will work locally.
- app/views/comments/index.html.erb - The adjustment to the view I added to make the Stimulus controller activate.
- app/jobs/partials/comments/list_job.rb - The ActiveJob where I broadcast the updated partial via ActionCable.
- test/system/comments/realtime_partials_test.rb - The system test for the realtime partials.
Setting up locally
Pull down the repo & run:
brew install redis ./bin/setup
brew install redisYou will need redis installed on your local machine & have it running for ActionCable to work.
bin/setup- runs bundler & yarn, then sets up the database.
Next you should be able to run:
To turn on the server, your port may vary but if you visit http://localhost:3000/comments you should be able to see the realtime updates when CRUD'ing objects.