我重新安装了发布和取消发布帖子的刺激反射。但是这个按钮不工作,它在控制台中给了我这个错误。我不知道哪里出错了。
stimulus_reflex.js
var StimulusReflexController = /*#__PURE__*/function (_Controller) {
_inherits(StimulusReflexController, _Controller);
var _super = _createSuper(StimulusReflexController);
function StimulusReflexController() {
var _this;
_classCallCheck(this, StimulusReflexController);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
register(_assertThisInitialized(_this));
return _this;
}
return StimulusReflexController;
}(Controller); // Sets up declarative reflex behavior.
// Any elements that define data-reflex will automatically be wired up with the default StimulusReflexController.
//
,这是utils.js
export var debounce = function debounce(callback) {
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
var timeoutId;
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
clearTimeout(timeoutId);
timeoutId = setTimeout(function () {
timeoutId = null;
callback.apply(void 0, args);
}, delay);
};
};
这是我的publisher_reflex.rb
class PublisherReflex < ApplicationReflex
def toggle
post = Post.find(element.dataset[:post_id])
post.published? ? post.update(published: false, published_at: nil) : post.update(published: true, published_at: Time.now)
end
end
这是edit.html.rb
<div class="card-footer">
<% if @post.published? %>
<a href="#"
class='btn btn-warning col-12'
data-reflex ='click->PublisherReflex#unpublish'
data-post-id = '<%= @post.id %>'
>
Unpublish
</a>
<% else %>
<a href="#" class="btn btn-dark col-12"
data-reflex='click->PublisherReflex#publish'
data-post-id = '<%= @post.id %>'
>
Publish
</a>
<%end%>
</div>
你有Redis服务器在后台运行吗?这解决了我的问题,同时手动重新安装刺激反射。
https://docs.stimulusreflex.com/hello-world/setup