jimsynz / faye-rails

Simple Rails glue for the Faye messaging protocol.
MIT License
435 stars 79 forks source link

Model Observe Cann't Publish #75

Open edwinlab opened 9 years ago

edwinlab commented 9 years ago

Hi i have problem with faye-rails, my gemfile

gem 'rails', '>= 4.0.1'
gem 'faye-rails', '~> 2.0.1'
gem 'thin'

My controller example

class NotifController < FayeRails::Controller

  observe Notification, :after_create do |notification|
    NotifController.publish("/notification/1", "tets")
    Rails.logger.info('------------------AFTER CREATE NOTIF SESSION ------------------')
  end

  channel '/notification/*' do
    monitor :subscribe do
      Rails.logger.info('------------------MONITOR SUBSCRIBE----')
    end

    monitor :publish do
      Rails.logger.info('------------------MONITOR PUBLISH----')
    end

    monitor :unsubscribe do
    end
  end
end

And in view

<script>
      var client = new Faye.Client('/faye');
      client.subscribe('/notification/1', function(data) {
        console.log(data);
      });
 </script>

Observe model can't publish to client it call when notif create, i try publish in client it works but not in model, please help. Thanks

console

  SQL (0.6ms)  INSERT INTO `notifications` (`created_at`, `notify_id`, `notify_type`, `profile_id`, `state`, `updated_at`) VALUES ('2015-03-24 07:08:18', 1, 'ocr_processes', 1, 'ocr', '2015-03-24 07:08:18')
------------------AFTER CREATE NOTIF SESSION ------------------
<script>
      var client = new Faye.Client('/faye');
      client.publish('/notification/1', "test");
 </script>
toomus commented 9 years ago

To help you I must know, what actually Faye is receive and send. You must add extension to your Faye with incoming() and outgoing() functions, where you can monitor Faye message traffic. Do this, and come back with results :)