-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Action cable gf #28
Action cable gf #28
Changes from all commits
e65efc2
22d0127
d2d7687
44b38ff
ca60276
f90f895
34c54d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class SocialChannel < ApplicationCable::Channel | ||
def subscribed | ||
social = Social.first | ||
stream_for social | ||
# stream_from "some_channel" | ||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,21 @@ class Api::V1::SocialController < ApplicationController | |
|
||
def index | ||
messages = Message.all | ||
|
||
render json: messages | ||
end | ||
|
||
def create | ||
|
||
user = User.find_by(name: params[:name]) | ||
channel = Social.first | ||
message = Message.create!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like how you broke this down for readability. |
||
content: params[:content], | ||
name: user.name, | ||
social_id: channel.id, | ||
user_id: user.id | ||
) | ||
|
||
SocialChannel.broadcast_to(channel, message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great formatting of the broadcasting the desired information. |
||
render json: message | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class Message < ApplicationRecord | ||
validates_presence_of :content | ||
belongs_to :user | ||
|
||
belongs_to :social | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Social < ApplicationRecord | ||
has_many :messages | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateSocials < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :socials do |t| | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddSocialsToMessages < ActiveRecord::Migration[5.2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully this is all we need to get WebSockets live! |
||
def change | ||
add_reference :messages, :social, foreign_key: true | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryBot.define do | ||
factory :social do | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Social, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic method in going about the group social channel.