gpt4 book ai didi

ruby-on-rails - rails : How do I re-render a partial view on a page?

转载 作者:行者123 更新时间:2023-12-04 03:45:36 25 4
gpt4 key购买 nike

我有一个带有按钮并显示一些信息的局部 View 的网页。当用户单击此局部 View 中的按钮时,我需要能够在被调用的操作中从 Controller 更新该局部 View 。具体来说,有一个字符串我想更新。到目前为止,这是我的代码,但它不起作用..

部分 View (_printLabel.rhtml)

<% if @printAsinEnabled %>
<%= check_box_tag(:needPrint, :needPrint, false,
:onchange => "if (this.checked) $('printLabelAction').show(); else $('printLabelAction').hide();") %>
<%=_('Need to print label?')%><br /><br />
<div id="printLabelAction" class="action" style="display:none;">
<% onPrintLabelClick = generateAjaxRequest(
{:controller => @controller.controller_name,
:action => 'processPrintLabelRequest',
:creturnWipItemId => creturnWipItemId,
:barcode => collectedItemData.fnsku,
:title => asinInfo["title"]},
["parameters: Form.serializeElements([$('printerAddress'),$('printerRemote_true'),$('printerRemote_false')])"]) %>
<%=_('Printing')%>: <%= collectedItemData.fnsku %> <br /> <br />
<%= radio_button_tag(:printerRemote, :false, !session[:printRemote]) %>
<label for="printerRemote_false"><%=_('Local Printer')%></label> <br />
<%= radio_button_tag(:printerRemote, :true, session[:printRemote]) %>
<label for="printerRemote_true"><%=_('Remote Printer')%> - <%=_('Printer Address')%>:</label>
<%= text_field_tag(:printerAddress, session[:printerAddress],
:onchange => onPrintLabelClick,
:onclick => "$('printerRemote_true').checked = true")%> <br />
<div style="text-align:right;">
<%= button_to_function(_("Print Label"), onPrintLabelClick) %>
</div>
<%=_('Error?')%>: <%= errorMessage %> <br /> <br />
</div>

这是它最初呈现的 div:

<div id="Block_asinSummary" class="block">
...
...
<td height="200px" width ="70%">
<%= link_to asinInfo["title"], asinInfo["link"], :target => "_blank" %><br/><br/>
<% if !asinInfo["clothingSize"].nil? %>
<b><%= _('Size')%>:&nbsp</b> <%= asinInfo["clothingSize"]%><br>
<% end %>
<font size='1'>
<% sku = collectedItemData.displaySku %>
<% if sku != collectedItemData.asin%>
<b>SKU:</b> <%= sku %><br>
<% else %>
<b>ASIN:</b> <%= collectedItemData.asin %>
<% end %>

<%= render(:partial => 'printLabel', :locals => { :creturnWipItemId => creturnWipItemId, :collectedItemData => collectedItemData, :asinInfo => asinInfo, :errorMessage => "HI" })%>
</font>
</td>
</tr>
</table>
...
...
<% end %>

这里是应该在点击时用新字符串更新“errorMessage”的 Controller 代码:

render(:partial => 'printLabel', :layout => false, :locals => { :creturnWipItemId => creturnWipItemId, :collectedItemData => @collectedItemData, :asinInfo => asinInfo, :errorMessage => "Bye" })

我没有看到任何错误,但是 errorMessage 字符串没有从“HI”更新为“Bye”。

最佳答案

您不能从您的 Controller 调用 render partial。相反,呈现模板并使用实例变量将不同的错误消息传递给部分。

关于ruby-on-rails - rails : How do I re-render a partial view on a page?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9203881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com