i use rails 6 on heroku and when i preform a reflex action the console logs:
i try to create a Mifal when i select a radio button what can i do?
Error invoking action "change->stimulus-reflex#__perform"
"The ActionCable connection is not open! `this.isActionCableConnectionOpen()` must return true before calling `this.stimulate()`"
the code:
more_info.html.erb:
<div class='preps'>
<%= f.input :heads_prep, label_html: {class:"label"}, item_wrapper_class: "radio-label", input_html: {data: {reflex:"change->preps#toggle_prep", "prepValue": 'heads', activity: @activity.id}}, collection: Activity.heb_preps.map{ |k, v| [v, k] }, as: :radio_buttons %>
<%= f.input :guides_prep, label_html: {class:"label"}, item_wrapper_class: "radio-label", input_html: {data: {reflex:"change->preps#toggle_prep", "prepValue": 'guides', activity: @activity.id}}, collection: Activity.heb_preps.map{ |k, v| [v, k] }, as: :radio_buttons %>
</div>
preps_reflex.rb:
# frozen_string_literal: true
class PrepsReflex < ApplicationReflex
delegate :current_user, to: :connection
def toggle_prep
activity = Activity.find(element.dataset.activity)
prep = element.dataset.prepvalue
if element.value == 'yes'
puts prep
activity.update("#{prep}_prep": :yes)
unless activity.heads_mifal.present?
activity.mifals.create(name: "#{Mifal.heb_mifal_type(prep)} #{activity.name}", mifal_type: prep)
end
else
activity.update("#{prep}_prep": :no)
activity.mifals.find_by(mifal_type: prep).destroy
end
# morph "#preps", "Your muscles... they are so tight."
end
end
i use devise: connection.rb:
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
protected
def find_verified_user
if (current_user = env["warden"].user)
current_user
else
reject_unauthorized_connection
end
end
end
end