title: Using Private-pub with channels that have segment keys and coffeescript variant
body: <p>I'm trying to replicate a push notification system similar to facebook's using <a href="https://github.com/ryanb/private_pub" rel="nofollow noreferrer">private_pub</a>. Ideally I would want to link this to show notifications using a gem such as <a href="https://github.com/RobinBrouwer/gritter" rel="nofollow noreferrer">gritter</a> (other gem suggestions are welcome)</p>
  
  <p>Whenever a certain action from a controller is called, I want to send a notification to all subscribers that are part of a specific id. As long you are logged in, you are subscribed to the channel, achieved by putting the <code>subscribe_to</code> in the layouts.</p>
  
  <p>in the view:</p>
  
  <pre><code>&lt;%= subscribe_to "/messages/#{@group_id}" %&gt;
  </code></pre>
  
  <p>in the controller </p>
  
  <pre><code>PrivatePub.publish_to("/messages/#{@group_id}", "alert('test')")
  </code></pre>
  
  <p>this works just fine, however I would like to have something more sophisticated than an <code>alert</code> as a response (such as a gritter notification), so instead:</p>
  
  <pre><code>PrivatePub.publish_to("/messages/#{@group_id}", data: @some_data)
  </code></pre>
  
  <p>Following the <a href="http://railscasts.com/episodes/316-private-pub" rel="nofollow noreferrer">tutorial</a>, they use coffeescript for this. However, I cannot get the simple alert going (probably due to the id in the channel)</p>
  
  <p>In <a href="https://stackoverflow.com/questions/17201127/how-can-i-use-private-pub-with-a-resource-route-that-has-a-segment-key">this</a> question, the OP was able to solve this using a js.erb view. But I can't get it to work.</p>
  
  <p>disclaimer: my js and coffeescript knowledge is almost zero.</p>
  
  <p>Any help is appreciated :)</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>Some more info: I've a method in a controller that's part of a public API, and expects POST request. If everything is ok it sends out a JSON success response. Aside from this, the same method sends a notification to all users of a specific group.</p>
  
  <p>I've actually managed to get this working, putting this in the controller:</p>
  
  <p>callback method:</p>
  
  <pre><code>respond_to do |format|
      format.js #-&gt; calls callback.js.erb
      #format.json { render json: {"success" =&gt; true}.to_json }
  end
  </code></pre>
  
  <p>and putting the gritter stuff in <code>my_api_controller/callback.js.erb</code>:</p>
  
  <pre><code>&lt;% publish_to "/messages/#{@group_id}" do %&gt;
      &lt;%= add_gritter(
      "Nova " + link_to("reserva", reservation_path(@r)) + " de #{@channel} para " + 
      link_to(@hostel_name, hostel_path(@hostel_id)),
      :title =&gt; "Nova reserva!",
      :sticky =&gt; true,
      :image =&gt; :notice
  ) %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>note: since the subscription to the channel is done in every view (through the layout), you can receive a notification on any page/view</p>
  
  <p>My problem at the momento is, as you can guess, the JSON response. Since I cant render two responses, only the js.erb is called, but the JSON response is never sent</p>