Module: Pushkin::ActionView::Helpers
- Defined in:
- lib/pushkin/action_view/helpers.rb
Instance Method Summary collapse
-
#publish_to(channel, data = nil, &block) ⇒ Object
Publish the given data or block to the client by sending a Faraday POST request to the Faye server.
-
#subscribe_to(channel) ⇒ Object
Subscribe the client to the given channel.
Instance Method Details
#publish_to(channel, data = nil, &block) ⇒ Object
Publish the given data or block to the client by sending a Faraday POST request to the Faye server. If a block or string is passed in, it is evaluated as JavaScript on the client. Otherwise it will be converted to JSON for use in a JavaScript callback.
10 11 12 |
# File 'lib/pushkin/action_view/helpers.rb', line 10 def publish_to(channel, data = nil, &block) PrivatePub.publish_to(channel, data || capture(&block)) end |
#subscribe_to(channel) ⇒ Object
Subscribe the client to the given channel. This generates some JavaScript calling PrivatePub.sign with the subscription options.
17 18 19 20 21 22 |
# File 'lib/pushkin/action_view/helpers.rb', line 17 def subscribe_to(channel) subscription = PrivatePub.subscription(:channel => channel) content_tag "script", :type => "text/javascript" do raw("PrivatePub.sign(#{subscription.to_json});") end end |