This file contains 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
# The models | |
class TextMessage < ApplicationRecord | |
belongs_to :account, inverse_of: :text_messages, optional: true | |
belongs_to :user, inverse_of: :text_messages, optional: true | |
has_many :phones, ->(text_message) { joins(name: :products).where("products.account_id = ?", text_message.account_id) }, foreign_key: :number, primary_key: :client_phone_number | |
has_many :names, through: :phones, source: :name | |
class Phone < ApplicationRecord | |
belongs_to :name, inverse_of: :phones |
This file contains 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
Version4::Foo.last.bars.first.class | |
=> Version4::Bar | |
Version5::Foo.last.bars.first.class | |
=> Version4::Bar | |
This file contains 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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails" |
This file contains 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
class ArticleChannel < ApplicationCable::Channel | |
def subscribed | |
@article = Article.find(params[:article_id]) | |
@editor_id = params[:editor_id] | |
# Write it only if the editor is truly nil in a single query to avoid race conditions | |
Article.where(id: @article.id, editor: nil).update(editor: @editor_id) | |
stream_for @article |
OlderNewer