Pusher不会在Heroku Rails应用程序上触发,但在localhost:3000上可以正常工作

问题描述 投票:1回答:2

[我正在Ruby on Rails应用程序上学习Pusher,并在用户单击按钮的地方进行设置,它会提交表单以更新对象,然后触发Pusher事件,该事件发送警报并更改所有正在监听的窗口的背景色该频道。

我的站点在本地服务器localhost:3000和Heroku上运行。在localhost:3000上,这就像一种魅力-当我打开在本地和Heroku上运行站点的窗口时,单击本地站点上的按钮,所有窗口都会收到警报并更新背景色。

但是,当我在Heroku上尝试相同的操作时,没有一个窗口会收到警报或更改颜色。我查看了Pusher上的调试控制台,它显示已建立连接,但未显示已发送的API请求:

Subscribed    35329.28868505   Channel:  client-open    23:52:33
Connection    35329.28868505   Origin:   http://testing-pusher.herokuapp.com    23:52:33
Disconnection  35303.28886132  Channels: client-open, Lifetime: 107.70291038s   23:52:32

Heroku's help page,我已经安装了pusher gem和插件。

这是我的触发器,在我的switches#update中运行:

@switch.update(color: params[:switch][:color])
Pusher['client-open'].trigger('new_message', {:color => @switch.color})

在application.html.erb上运行的侦听器/绑定:

<script type="text/javascript" charset="utf-8">
$(function() {
    Pusher.log = function(message) {
        if (window.console && window.console.log) {
            window.console.log(message);
        }
    };

    var pusher = new Pusher('my_pusher_key'); // This has my actual key in it
    var channel = pusher.subscribe('client-open');
    channel.bind('new_message', function(data) {
        alert("I'm going to change your background color to #"+data.color);
        $("#appended").append("I'm going to change your background color to "+data.color);
        $(".color").css('background-color', '#'+data.color);
});

// Some useful Pusher debug msgs
pusher.connection.bind('connecting', function() {
    $('div#status').text('Connecting to Pusher...');
});

pusher.connection.bind('connected', function() {
    $('div#status').text('Connected to Pusher!');
});
    pusher.connection.bind('failed', function() {
      $('div#status').text('Connection to Pusher failed :(');
    });
    channel.bind('subscription_error', function(status) {
      $('div#status').text('Pusher subscription_error');
    });
  });
</script>

我在同一文件的标题中具有这两个脚本:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://js.pusherapp.com/2.0/pusher.min.js"></script>

我如何让Pusher在Heroku上正确触发?

编辑:这是Heroku日志。没有错误可以告诉我:

2014-05-07T18:40:46.291870+00:00 heroku[router]: at=info method=POST path=/switches/1 host=testing-pusher.herokuapp.com request_id=f3f9e17c-086b-4639-88ba-4a406828c4e7 fwd="24.20.217.80" dyno=web.1 connect=2ms service=72ms status=302 bytes=942
2014-05-07T18:40:46.224270+00:00 app[web.1]: Started PATCH "/switches/1" for 24.20.217.80 at 2014-05-07 18:40:46 +0000
2014-05-07T18:40:46.224278+00:00 app[web.1]: Started PATCH "/switches/1" for 24.20.217.80 at 2014-05-07 18:40:46 +0000
2014-05-07T18:40:46.227649+00:00 app[web.1]: Processing by SwitchesController#update as HTML
2014-05-07T18:40:46.415613+00:00 app[web.1]: Started GET "/" for 24.20.217.80 at 2014-05-07 18:40:46 +0000
2014-05-07T18:40:46.455745+00:00 app[web.1]: Completed 200 OK in 28ms (Views: 19.0ms | ActiveRecord: 1.4ms)
2014-05-07T18:40:46.230175+00:00 app[web.1]: Processing by SwitchesController#update as HTML
2014-05-07T18:40:46.424400+00:00 app[web.1]: Processing by SwitchesController#show as HTML
2014-05-07T18:40:46.451080+00:00 app[web.1]:   Rendered switches/_form.html.haml (7.4ms)
2014-05-07T18:40:46.230262+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"nqhkV37GG6ym+pM7j+Bdxh3aBltTLfNpPa6cnE6b92U=", "switch"=>{"color"=>"c4b6c2"}, "commit"=>"push me", "id"=>"1"}
2014-05-07T18:40:46.230298+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"nqhkV37GG6ym+pM7j+Bdxh3aBltTLfNpPa6cnE6b92U=", "switch"=>{"color"=>"c4b6c2"}, "commit"=>"push me", "id"=>"1"}
2014-05-07T18:40:46.287569+00:00 app[web.1]: Redirected to http://testing-pusher.herokuapp.com/
2014-05-07T18:40:46.287617+00:00 app[web.1]: Redirected to http://testing-pusher.herokuapp.com/
2014-05-07T18:40:46.287866+00:00 app[web.1]: Completed 302 Found in 57ms (ActiveRecord: 8.2ms)
2014-05-07T18:40:46.287875+00:00 app[web.1]: Completed 302 Found in 57ms (ActiveRecord: 8.2ms)
2014-05-07T18:40:46.409915+00:00 app[web.1]: Started GET "/" for 24.20.217.80 at 2014-05-07 18:40:46 +0000
2014-05-07T18:40:46.423250+00:00 app[web.1]: Processing by SwitchesController#show as HTML
2014-05-07T18:40:46.451349+00:00 app[web.1]:   Rendered switches/show.html.haml within layouts/application (12.7ms)
2014-05-07T18:40:46.446554+00:00 app[web.1]:   Rendered switches/_form.html.haml (7.4ms)
2014-05-07T18:40:46.452492+00:00 app[web.1]: Completed 200 OK in 28ms (Views: 19.0ms | ActiveRecord: 1.4ms)
2014-05-07T18:40:46.451312+00:00 app[web.1]:   Rendered switches/show.html.haml within layouts/application (12.7ms)

该项目现在在testing-pusher.herokuapp.com上进行。

javascript jquery ruby-on-rails heroku pusher
2个回答
0
投票

您在Heroku日志中看到任何错误或消息吗?

而且,您是否在Heroku上尝试了一个简单的测试用例,除了通过Pusher gem发送消息外,什么也没有做?


0
投票

我认为您需要更改Pusher应用程序凭据。

© www.soinside.com 2019 - 2024. All rights reserved.