ruby-on-rails - 刺激反射错误调用动作“change->stimulus-reflex#__perform”
问题描述
我在heroku上使用rails 6,当我执行反射动作时,控制台记录:
当我选择一个单选按钮时,我尝试创建一个 Mifal 我该怎么办?
Error invoking action "change->stimulus-reflex#__perform"
"The ActionCable connection is not open! `this.isActionCableConnectionOpen()` must return true before calling `this.stimulate()`"
编码:
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
我使用设计: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
解决方案
推荐阅读
- php - Mamp PHP 空白页
- c++ - deque 迭代器在调试模式下不可取消引用错误
- python - 如何替换打印以避免在输出中打印 NONE?
- javascript - 为什么从另一个方法调用方法时出现“TypeError:this.X is not a function”?
- c# - 如何在 C# 中使用 UDP 发送发布请求?
- python - 如果一个字符串列包含在 Pandas 的另一列中,则合并两个数据框
- javascript - 在 JavaScript 中将表导出为 file.txt
- javascript - TypeScript:复选框输入的正确“HTML 类型”是什么?
- python - 使用 requests.get() python 时出现 403 错误
- java - Maven - 在war文件的根目录中包含外部资源