Skip to content

Commit

Permalink
Add ActionCable
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Oct 23, 2024
1 parent 46337bb commit e258059
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/cache/
/config/*.deployed
/config/aliases
/config/cable.yml
/config/config.tmp
/config/crontab
/config/database.yml
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ gem 'matrix', '~> 0.4.2'
gem 'mini_magick', '~> 4.13.1'
gem 'net-protocol', '~> 0.1.3'
gem 'redcarpet', '~> 3.6.0'
gem 'redis', '~> 4.8.1'
gem 'rolify', '~> 6.0.1'
gem 'ruby-msg', '~> 1.5.0', git: 'https://github.com/mysociety/ruby-msg.git', branch: 'ascii-encoding'
gem 'rubyzip', '~> 2.3.2'
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ DEPENDENCIES
rails-i18n (~> 7.0.5)
recaptcha (~> 5.17.0)
redcarpet (~> 3.6.0)
redis (~> 4.8.1)
rolify (~> 6.0.1)
rspec-activemodel-mocks (~> 1.2.1)
rspec-rails (~> 7.0.1)
Expand Down
4 changes: 4 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
4 changes: 4 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions app/javascript/channels/consumer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { createConsumer } from "@rails/actioncable"
export default createConsumer()
1 change: 1 addition & 0 deletions app/javascript/channels/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Import all the channels to be used by Action Cable
1 change: 1 addition & 0 deletions app/javascript/modern_application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails";
import "channels";
import "controllers";

// Disable old jQuery UJS event handling, allowing Turbo to handle instead
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# require "action_mailbox/engine"
require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

Expand Down
12 changes: 12 additions & 0 deletions config/cable.yml-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
development:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: alaveteli_development

test:
adapter: test

production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: alaveteli_production
1 change: 1 addition & 0 deletions config/general.yml-example
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ SHARED_FILES_PATH: ''
#
# ---
SHARED_FILES:
- config/cable.yml
- config/database.yml
- config/general.yml
- config/sidekiq.yml
Expand Down
2 changes: 2 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@rails/actioncable", to: "actioncable.esm.js"
pin "sortablejs" # @1.15.2

pin "modern_application"
pin_all_from "app/javascript/channels", under: "channels"
pin_all_from "app/javascript/controllers", under: "controllers"
pin_all_from "app/javascript/helpers", under: "helpers"
1 change: 1 addition & 0 deletions docker/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fi
success_msg 'done'

notice_msg "Copying example files..."
[ ! -f config/cable.yml ] && cp config/cable.yml-example config/cable.yml
[ ! -f config/database.yml ] && cp config/database.yml-example config/database.yml
[ ! -f config/sidekiq.yml ] && cp config/sidekiq.yml-example config/sidekiq.yml
[ ! -f config/storage.yml ] && cp config/storage.yml-example config/storage.yml
Expand Down
3 changes: 3 additions & 0 deletions script/install-as-user
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ do
fi
done

# add cable.yml
cp config/cable.yml-example config/cable.yml

# add sidekiq.yml
cp config/sidekiq.yml-example config/sidekiq.yml

Expand Down

0 comments on commit e258059

Please sign in to comment.