This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| module ActiveStorage | |
| class Engine < Rails::Engine | |
| ... | |
| config.active_storage.variable_content_types = %w( | |
| image/png | |
| image/gif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/jobs/update_leaderboard_job.rb | |
| class UpdateLeaderboardJob < ApplicationJob | |
| queue_as :default | |
| delegate :render, to: :ApplicationController | |
| include CableReady::Broadcaster | |
| def perform | |
| scores = ServiceForFetchingScores.fetch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/channels/leaderboard_channel.rb | |
| class LeaderboardChannel < ApplicationCable::Channel | |
| def subscribed | |
| stream_for 'scores' | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/services/importers/users.rb | |
| module Importers | |
| class Users | |
| include CableReady::Broadcaster | |
| def initialize(file:) | |
| @file = file | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // app/javascript/channels/user_channel.js | |
| import consumer from "./consumer"; | |
| import CableReady from "cable_ready"; | |
| consumer.subscriptions.create("UserChannel", { | |
| received(data) { | |
| if (data.cableReady) CableReady.perform(data.operations); | |
| // Called when there's incoming data on the websocket for this channel | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/channels/user_channel.rb | |
| class UserChannel < ApplicationCable::Channel | |
| def subscribed | |
| stream_for current_user | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/services/importers/users.rb | |
| module Importers | |
| class Users | |
| include CableReady::Broadcaster | |
| ... | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/services/importers/users.rb | |
| module Importers | |
| class Users | |
| def initialize(file:) | |
| @file = file | |
| end | |
| def import_csv | |
| CSV.foreach(@file.path, headers: true) do |csv_row| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def results | |
| … | |
| cable_ready.morph( | |
| children_only: true, | |
| selector: '#id_of_a_dom_element', | |
| html: render( | |
| PaginationComponent.new( | |
| pagy: pagy, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def results | |
| params_hash = element.dataset['params-hash'].present? ? JSON.parse(element.dataset['params-hash']) : filtered_params | |
| query = (element.dataset.from_search_input ? element.value : element.value.presence) || params_hash['query'] | |
| params_hash['query'] = query | |
| pagy, collection = pagy(active_record_collection(filters), page: page) | |
| cable_ready.morph( | |
| children_only: true, | |
| selector: '#id_of_a_dom_element', | |
| html: render( |