本地环境功能已正常运行。发布到 test 环境后,前台无反应。test 环境 redis,puma 正常,后台可以看到广播发送了。这是我的前端订阅消息的代码:
var Notices = React.createClass({
getInitialState: function() {
return {
requests: []
};
},
renderRequest: function(request) {
return (
<li>
<a href="#">
<div>
<i className="fa fa-tasks fa-fw"></i> {request.id}
<span className="pull-right text-muted small">{request.created_at}</span>
</div>
</a>
</li>
);
},
componentDidMount: function() {
this.setupSubscription();
},
updateRequests: function(request) {
var requests = React.addons.update(this.state.requests, { $push: [request]});
this.setState({requests: requests, style: {color: 'red'}});
},
setupSubscription: function(){
App.requests = App.cable.subscriptions.create("RequestsChannel", {
received: function (data) {
this.updateRequests(data.request);
},
updateRequests: this.updateRequests
});
},
check: function() {
this.setState({style: {color: ''}});
},
render: function() {
return (
<div onClick={this.check}>
<a className="dropdown-toggle" data-toggle="dropdown" href="#" style={this.state.style}>
<i className="fa fa-bell fa-fw"></i>{this.state.requests.length > 0 ? this.state.requests.length : null}
</a>
</div>
);
}
});
求指导!如果需要额外信息请留言。