diff --git a/app/channels/count_channel.rb b/app/channels/count_channel.rb new file mode 100644 index 0000000..131c501 --- /dev/null +++ b/app/channels/count_channel.rb @@ -0,0 +1,9 @@ +class CountChannel < ApplicationCable::Channel + def subscribed + # stream_from "some_channel" + end + + def unsubscribed + # Any cleanup needed when channel is unsubscribed + end +end diff --git a/app/javascript/application.js b/app/javascript/application.js index 3016c21..f4a553e 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -2,3 +2,4 @@ import "@hotwired/turbo-rails" import "./controllers" import * as bootstrap from "bootstrap" +import "./channels" diff --git a/app/javascript/channels/consumer.js b/app/javascript/channels/consumer.js new file mode 100644 index 0000000..8ec3aad --- /dev/null +++ b/app/javascript/channels/consumer.js @@ -0,0 +1,6 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command. + +import { createConsumer } from "@rails/actioncable" + +export default createConsumer() diff --git a/app/javascript/channels/count_channel.js b/app/javascript/channels/count_channel.js new file mode 100644 index 0000000..2204e38 --- /dev/null +++ b/app/javascript/channels/count_channel.js @@ -0,0 +1,16 @@ +import consumer from "./consumer" + +consumer.subscriptions.create("CountChannel", { + connected() { + // Called when the subscription is ready for use on the server + console.warn("Connected to CountChannel."); + }, + + disconnected() { + // Called when the subscription has been terminated by the server + }, + + received(data) { + // Called when there's incoming data on the websocket for this channel + } +}); diff --git a/app/javascript/channels/index.js b/app/javascript/channels/index.js new file mode 100644 index 0000000..4b9f0ca --- /dev/null +++ b/app/javascript/channels/index.js @@ -0,0 +1,2 @@ +// Import all the channels to be used by Action Cable +import "./count_channel" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d5ad248..26b6daa 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,7 +11,24 @@
+<%= notice %>
<%= alert %>
diff --git a/config/application.rb b/config/application.rb index a9ab79d..ea5926a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,5 +18,9 @@ module CountAnything # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") + I18n.available_locales = [:en, :fr] + + # Set default locale to something other than :en + I18n.default_locale = :fr end end diff --git a/config/locales/en/fields.en.yml b/config/locales/en/fields.en.yml new file mode 100644 index 0000000..e278243 --- /dev/null +++ b/config/locales/en/fields.en.yml @@ -0,0 +1,5 @@ +en: + fields: + home: "Home" + login: "Login" + logout: "Logout" \ No newline at end of file diff --git a/config/locales/fr/fields.fr.yml b/config/locales/fr/fields.fr.yml new file mode 100644 index 0000000..0fd0842 --- /dev/null +++ b/config/locales/fr/fields.fr.yml @@ -0,0 +1,5 @@ +fr: + fields: + home: "Accueil" + login: "Se connecter" + logout: "Se déconnecter" diff --git a/package.json b/package.json index 6b90366..4bb702c 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "@hotwired/stimulus": "^3.2.1", "@hotwired/turbo-rails": "^7.2.5", "@popperjs/core": "^2.11.6", + "@rails/actioncable": "^7.0.4-2", "bootstrap": "^5.2.3", "bootstrap-icons": "^1.10.3", "esbuild": "^0.17.5", diff --git a/test/channels/count_channel_test.rb b/test/channels/count_channel_test.rb new file mode 100644 index 0000000..1bc95f3 --- /dev/null +++ b/test/channels/count_channel_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class CountChannelTest < ActionCable::Channel::TestCase + # test "subscribes" do + # subscribe + # assert subscription.confirmed? + # end +end diff --git a/yarn.lock b/yarn.lock index 54e8d41..5990ac2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -140,6 +140,11 @@ resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-7.0.4.tgz#70a3ca56809f7aaabb80af2f9c01ae51e1a8ed41" integrity sha512-tz4oM+Zn9CYsvtyicsa/AwzKZKL+ITHWkhiu7x+xF77clh2b4Rm+s6xnOgY/sGDWoFWZmtKsE95hxBPkgQQNnQ== +"@rails/actioncable@^7.0.4-2": + version "7.0.4-2" + resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-7.0.4-2.tgz#d69d1314c5bb1c8b51f7eeef98e1db5bab80caba" + integrity sha512-mMmDa9pJczGN+bX4nPgrmu+PHqKDpokfwSLF3Sk5h6Z996miFmPAg44F2TvG7koJQQ0YFXEVeHshRXVg5jmshQ== + anymatch@~3.1.2: version "3.1.3" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e"