Answer the question
In order to leave comments, you need to log in
How to properly update object in coffee script?
In general, I’m sawing the notification system and I won’t finish it in any way! :0
Everything works, except that I can't update new notifications in live mode
. I use private_pub and can't figure out how to correctly pass the object to the coffee script
. We have the following
aplication_controller.rb
before_filter :activity
def track_activity(user, trackable, action = params[:action], author = current_user)
Activity.create! user: user, trackable: trackable, action: action, author: author
PrivatePub.publish_to("/messages/new", cool: activity)
end
def activity
if signed_in?
@activities = current_user.activities.includes(:trackable).order(created_at: :desc)
end
end
end
<div class="user-notification">
<a class="fa fa-life-ring fa-lg" href="javascript:void(0);" tabindex="1"></a>
<div class="activity activity_open" id="activity">
<% @activities.each do |activity| %>
<%= link_to activity.user.name, activity.user %>
<%= render "activities/#{activity.trackable_type.underscore}/#{activity.action}", activity: activity %>
<% end %>
<%= subscribe_to "/messages/new" %>
</div>
rivatePub.subscribe "/messages/new", (data, channel) ->
alert $("#activity").append("<%= data.cool = @activities %>");
Answer the question
In order to leave comments, you need to log in
here is the code
alert $("#activity").append("<%= data.cool = @activities %>");
console.log(data); # вывести в консоль, что пришло
$('#activity').append(data.cool);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question