我一直致力于在现有的Rails6应用程序中启动并运行刺激反射。成功!我有几个反射在行动,ActionCable正在做它的job...all好。然而,在反射成功并且刺激通过ActionCable通信之后,页面在我的眼前更新了重复的内容。
下面的表单只是触发了保存表单对象的反射。正如您所看到的,在刺激和/或Turbolinks重新呈现表单后,页面不正确。在本例中,它双重呈现表单的submit按钮。
我不明白为什么会发生这种情况,希望这里的人已经看到了这个双重渲染问题。
在此之前

之后

HTML
<%= block_card title: 'BILLING', footer: (link_to('Add Billing Detail', new_project_billing_detail_path(@project)) if policy(@project.billing_details.new).new?) do %>
<%= @alert %>
<%= form_with model: @billing_detail, html: { novalidate: true }, data: { reflex: "submit->BillingDetailReflex#submit" } do |form| %>
<% if @billing_detail.errors.any? %>
<% @billing_detail.errors.full_messages.each do |message| %>
<%= tag.li message %>
<% end %>
<% end %>
<div>
<%= form.text_field :date,
placeholer: 'Date',
required: true,
data: { reflex: "change->BillingDetailReflex#submit" } %>
<%= form.text_field :billing_code,
placeholer: 'Billing Code',
required: true,
data: { reflex: "change->BillingDetailReflex#submit" } %>
<%= form.text_field :project_id %>
<%= form.text_field :user_id, value: current_user.id %>
</div>
<%= form.submit %>
<% end %>
<% end %>Reflex
# frozen_string_literal: true
class BillingDetailReflex < ApplicationReflex
before_reflex do
@billing_detail = BillingDetail.new
@billing_detail.assign_attributes(billing_detail_params)
end
def submit
if @billing_detail.save!
@alert = "saved id:#{ @billing_detail&.id }"
else
@alert = 'NOT saved'
end
end
private
def billing_detail_params
params.require(:billing_detail).permit(
:date,
:billing_cycle,
:user_id,
:project_id
)
end
end发布于 2020-07-22 22:57:01
在使用新内容更新页面时,StimulusReflex似乎无法成功识别现有的表单元素。尝试向表单元素添加唯一id。
此外,StimulusReflex将发出JavaScript控制台消息来帮助您进行调试,但这需要显式启用。请参阅:https://docs.stimulusreflex.com/troubleshooting#logging
请加入我们的不和谐中,在那里你会找到许多有用的手。https://discord.gg/xFqhV5
https://stackoverflow.com/questions/62687847
复制相似问题