Learn Enough Society
Certificate of Course CompletionThis page certifies that mokubo has completed Learn Enough Action Cable to Be Dangerous! 🎉
greeting_doubler('hello, world!');
greeting_doubler = function(phrase) {
alert(phrase + " " + phrase);
};
Uncaught ReferenceError: greeting_doubler is not defined
'hello, world!'
in Listing 2.2 with '¡Hola, mundo!'
?
greeting_doubler = function(phrase) {
alert(phrase + " " + phrase);
};
greeting_doubler('¡Hola, mundo!');
¡Hola, mundo! ¡Hola, mundo!
message_appender = function(content) {
$('.messages-table').append(content);
}
$(document).on('turbolinks:load', function() {
message_appender('I\'m appended to CSS class .messages-table!');
});
I'm appended to CSS class .messages-table!
$(document).on('turbolinks:load', function() {
message_appender('I\'m from above lines of message_appender!');
});
message_appender = function(content) {
$('.messages-table').append(content);
}
I'm from above lines of message_appender!
message_appender
in Listing 2.8?
message_appender = content ->
$('#messages-table').append(content)
$(document).on 'turbolinks:load', ->
message_appender('hello, world! How\'s it going?')
Uncaught ReferenceError: content is not defined
data.content
with data.username
in Listing 3.5. Do you get the correct value?
App.room = App.cable.subscriptions.create "RoomChannel",
connected: ->
# Called when the subscription is ready for use on the server
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
alert data.username
alice
alert
in Listing 3.5 with a call to console.log
. Use your browser’s web inspector to confirm that the correct value appears in the console (data.username
if you completed the previous exercise, data.content
otherwise). If you don’t have any experience with web inspectors or consoles, use your technical sophistication (Box 1.1) to figure it out.
App.room = App.cable.subscriptions.create "RoomChannel",
connected: ->
# Called when the subscription is ready for use on the server
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
console.log data.username
alice
preventDefault
line in Listing 3.11?
f.submit
in Listing 3.9 to see if $('input').click()
still works.
<div class="message-input">
<%= form_for(@message, remote: true) do |f| %>
<%= f.text_area :content %>
<% end %>
</div>
logged_in?
to false
in Listing 4.1. This forces the system to execute the reject_unauthorized_connection
branch of the if
statement in find_verified_user
. Can you tell by looking at the Rails server log if it worked?
module ApplicationCable
class Connection < ActionCable::Connection::Base
include SessionsHelper
identified_by :message_user
def connect
self.message_user = find_verified_user
end
private
def find_verified_user
if flase
# current_user
else
reject_unauthorized_connection
end
end
end
end
An unauthorized connection attempt was rejected
console.log
to determine the value of the scrollHeight
in your current application. Hint: In most browsers, you can use console.log
and jQuery directly in the web inspector console.
> console.log($('#messages')[0].scrollHeight)
1212
undefined
Reference: https://javascriptio.com/view/350605/cannot-read-property-scrollheight-of-null
<div class="message">
<div class="message-user">
<%= message.user.username %>:
</div>
<div class="message-content">
<%= message.content + " foobar" %>
</div>
</div>
bob: hello foobar
main.sass
.
[Link text](Link URL or path)

SessionsHelper
(as in Listing 4.1) and then try using current_user
in Listing 5.7. What error do you get?
class RoomChannel < ApplicationCable::Channel
include SessionsHelper
def subscribed
stream_from "room_channel"
stream_from "room_channel_user_#{current_user.id}"
current_user
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
mentions
method.
require 'test_helper'
class MessageTest < ActiveSupport::TestCase
def setup
@message = users(:example).messages.build(content: "Lorem ipsum @example @nonexistant")
@user = users(:example)
end
test "should be valid" do
assert @message.valid?, @message.errors.full_messages
end
test "should not be blank" do
@message.content = " "
assert !@message.valid?
end
test "should mention valid" do
assert_includes(@message.mentions.to_s, @user.username)
assert_not_includes(@message.mentions.to_s, "nonexistant")
end
end
$ rails test
Running via Spring preloader in process 3314
Started with run options --seed 56767
Run options: --seed 56767--=---=---=---=---=---=---=---=---=---=---] 0% Time: 00:00:00, ETA: ??:??:??
# Running:
. 20/2: [===== ] 10% Time: 00:00:00, ETA: 00:00:0. 20/3: [======== ] 15% Time: 00:00:00, ETA: 00:00:0.. 20/5: [============== ] 25% Time: 00:00:00, ETA: 00:00:. 20/6: [================= ] 30% Time: 00:00:00, ETA: 00:00:0.. 20/8: [====================== ] 40% Time: 00:00:00, ETA: 00:00:.. 20/10: [============================ ] 50% Time: 00:00:00, ETA: 00:00:. 20/11: [============================== ] 55% Time: 00:00:00, ETA: 00:00:0. 20/12: [================================= ] 60% Time: 00:00:00, ETA: 00:00:0.. 20/14: [======================================= ] 70% Time: 00:00:00, ETA: 00:00:. 20/15: [========================================== ] 75% Time: 00:00:01, ETA: 00:00:0. 20/16: [============================================ ] 80% Time: 00:00:01, ETA: 00:00:0. 20/17: [=============================================== ] 85% Time: 00:00:01, ETA: 00:00:0. 20/18: [================================================== ] 90% Time: 00:00:01, ETA: 00:00:0. 20/19: [===================================================== ] 95% Time: 00:00:01, ETA: 00:00:0. 20/20: [=======================================================] 100% Time: 00:00:01, Time: 00:00:01
.
Finished in 1.18467s
20 tests, 39 assertions, 0 failures, 0 errors, 0 skips
Finished in 1.202936s, 16.6260 runs/s, 32.4207 assertions/s.
20 runs, 39 assertions, 0 failures, 0 errors, 0 skips
$
unless
from Listing 4.4 in Line 10 of Listing 5.10?
It's working for both with no errors
Get free access to all 10 Learn Enough courses (including the Ruby on Rails Tutorial) for 7 days!
We require a credit card for security purposes, but it will not be charged during the trial period. After 7 days, you will be enrolled automatically in the monthly All Access subscription.
BUT you can cancel any time and still get the rest of the 7 days for free!
All Learn Enough tutorials come with a 60-day 100% money-back guarantee.