-
New App
# new rails app rails _5.0.0.beta3_ new ac && cd ac # initialize Git git init && git add . # first commit git commit -am "initial commit"
-
Generate the Rooms Controller and Message Model
rails g controller rooms show rails g model message content:text rails db:migrate # commit git add . git commit -am "Rooms Crontroller and Message Model"
Add a test message:
Message.create content: 'hello world'
-
Update the routes to send root to rooms#show
routes.rb:
root to: 'rooms#show'
-
Start the server and open the browser and show that the app is up
rails server
-
Set up the controller method and message views
rooms_controller.rb:
def show @messages = Message.all end
show.html.erb
_message.html.erb
git add . git commit -am "Add rooms/message views"
-
Pop open the browser again
-
Generate our ActionCable room channel with 'speak' action:
rails g channel room speak
-
Uncomment App in cable.coffee and ActionCable mount in routes.rb
-
Implement received and speak in room.coffee
-
Implement speak in room_channel.rb
def speak(data) ActionCable.server.broadcast 'room_channel', data['message'] end
git add . git commit -am "ActionCable Enabled"
-
Restart Rails Server and Demo via JS console
-
Add form field and required JavaScript to send messages..
-
Remove
from room.coffee received method
-
Update channel 'speak' implementation to actually write to the db.
-
Generate Job to handle Broadcasts
rails g job BroadcastMessage
-
Add after_create_commit hook to send broadcast job.
after_create_commit { BroadcastMessageJob.perform_later self }
git add . git commit -am "Fin"
-
Restart rails server and demo working ActionCable in browser.
-
Set up devise
Add to the Gemfile:
gem 'devise', github: 'plataformatec/devise'
Install Devise and Generate User Model
bundle install rails g devise:install rails g devise User rails g migration AddUserToMessages user:references:index rails db:migrate git add . git commit -am "Devise and User Model"
-
Add belongs_to to Message Model:
message.rb:
belongs_to :user
-
Update add devise before_action to controller:
rooms_controller.rb:
before_action :authenticate_user!
-
Update v2 files
application.html.erb _message.html.erb room.coffee rooms.coffee show.html.erb
-
Explain current_user, warden config. Add warden hooks:
Populate: config/initializers/warden_hooks.rb connection.rb
-
Demonstrate in the browser. RESTART SERVER
-
v3 STYLE
-
Notifications
You must be signed in to change notification settings - Fork 17
jeffnappi/action-cable-chat
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
ActionCable Example App from my RubyAZ talk.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published