Uncaught TypeError: Cannot read property 'schema' of undefined at stimulus_reflex.js:328 at utils.js:50

625 Views Asked by At

I had reinstalled stimulus reflex for publishing and unpublishing a post. but the button is not working, it gives me that error in the console. I don't know where I went wrong.

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.
//

and this is 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);
  };
};

this is my 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

this is the 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>
1

There are 1 best solutions below

2
On

Do you have Redis server runnning in the background? That solved my issue, along with manually reinstalling stimulus reflex.

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