Home>
I want to see messages in real time
"[Rails6.0] Real-time chat creation with ActionCable and Devise greedy set (revised version)"
https://qiita.com/eRy-sk/items/4c4e983e34a44c5ace27
We make community type sns with rails based on this article.
And, community creation function was added to this.
It looks like the data is stored on the server.
I'm in trouble because the sent message doesn't appear.
Add community creation feature,
I confirmed the behavior after sending a message in the created community
The message is no longer updated in real time.
Before creating the community, it worked fine,
Applicable source codeapp/channels/community_channel.rb
class CommunityChannel</pre>
<p><br />
app/javascript/channels/community_channel.js</p>
<pre><code>import consumer from './consumer'
$(function () {
const chatChannel = consumer.subscriptions.create ({channel: 'CommunityChannel', community: $('# messages'). data ('community_id')}, {
connected () {
// Called when the subscription is ready for use on the server
},
disconnected () {
// Called when the subscription has been terminated by the server
},
received: function (data) {
return $('# messages'). append (data ['message']);
},
speak: function (message) {
return this.perform ('speak', {
message: message
});
}
});
// keypress where data-behavior is community_speaker ...
$(document) .on ('keypress', '[data-behavior ~ = community_speaker]', function (event) {
if (event.keyCode === 13) {
chatChannel.speak (event.target.value);
event.target.value = '';
return event.preventDefault ();
}
});
});
app/jobs/message_broadcast_job.rb
class MessageBroadcastJob</pre>
<p><br />
app/views/communities/show.html.erb</p>
<pre><code>">
<% = render @messages%>
<% = label_tag: content, @ community.name%>
<% = text_field_tag: content, nil, data: {behavior: 'community_speaker'}%>
app/views/messages/_message.html.erb
<p><% = "# {message.user.email}: # {message.content}"%></p>
What I did.
turbolinks removed.
-
Answer # 1
Related articles
- the view does not transition in the web app being created with ruby on rails
- ruby on rails - i'm a beginner i'm deploying an app created with rails on heroku, but i can't proceed with an error
- ruby on rails 6 - can i write font awesome in rails6 helper?
- about the empty model created by "new" of ruby on rails
- ruby on rails - rails6 rspec model run-time error nomethoderror: undefined method `valid?'for nil: nilclass
- ruby on rails 5 - f i want to prevent the logged-in user from being selected with collection_select
- ruby - i can't start the docker container with an app created with rails
- ruby - i want to prevent the information once selected from being displayed in the select box
- ruby on rails - rails not updated after editing update
- new project is not created in ruby on rails
- ruby on rails 6 - if you use multiple link_to in rails6 helper, only the last one will be reflected
- ruby on rails 6 - rails6 gives argumenterror in postscontroller # create
- ruby - do that row each time the rails model is updated
- ruby on rails 6 - rails6 activerecord :: recordinvalid in userscontroller # update
- [ruby on rails] i want to prevent a new group from being created if there is an existing group in the chat application
- ruby - in the api directory created to implement the incremental search, the id cannot be acquired properly! !!
- ruby on rails - how to upload something created with rails
- ruby on rails6 [devise] i don't want to be able to edit the profile of a user other than myself
- ruby on rails 6 - aws cloud9 blocks host on rails6
- ruby on rails - rails6 jquery image replacement (attachment_image_tag)
Related questions
- ruby - passing variables using render partial
- ruby version does not change
- ruby - dealing with validation errors when rendering rails apps (definition of instance variables)
- ruby - i get an error with the rails new command
- ruby - implementation of friendly forwarding
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby - about rails controller new action
- ruby - rails page does not open
- [ruby] i'm having trouble with nomethoderror
- ruby - [search function] acquisition of products associated with users
It was a spelling error.
Changed as follows.