0

我已经重新安装了用于发布和取消发布帖子的刺激反射。但按钮不起作用,它在控制台中给了我这个错误。我不知道我哪里错了。

刺激反射.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>
4

1 回答 1

0

你有 Redis 服务器在后台运行吗?这解决了我的问题,以及手动重新安装刺激反射。

https://docs.stimulusreflex.com/hello-world/setup

于 2021-08-13T12:03:46.197 回答