D
D
dexdev2014-10-09 12:39:46
Ruby on Rails
dexdev, 2014-10-09 12:39:46

How to bind js file to action in application controller?

There is an action in the application controller
application_controller.rb

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

the action is called from different controllers and generates notifications for users created a message, and so on, now you need to display all this in live mode using faye and private_pub,
the problem is that you need to link the js file with the following content:
<% publish_to "/messages/new" do %>
  $("#activity").append("<%= j render(@activities) %>");
<% end %>

Please tell me how to call it and where to save it so that it is always called when track_activity is used?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Emelyantsev, 2014-10-09
@Gambala

Personally, I have not worked with faye yet, but I recommend the article: habrahabr.ru/post/124066 - you need to write this js code in the faye view so that it sends it to your rails application, in the rails js application itself it can be like this:

$(function() {
  var faye = new Faye.Client('http://moesuperprilozhenie.ru:9292/faye');
  faye.subscribe("/orders/update", function(data) {
    eval(data);
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question