我有一個引導莫代爾點擊該鏈接時觸發:如何在點擊鏈接後將局部變量發送到局部渲染?
<a class="plus" href="javascript:;" data-toggle="modal" data-target="#myModal"> </a>
然後我有這個在我_footer.html.erb
<%= render 'shared/tag_users_modal' %>
,然後有這個標準的引導模態:
<!-- Modal -->
<div class="modal tagging fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Tag User</h4>
</div>
<div class="modal-body">
<%= simple_form_for @node, url: add_tagged_user_node_path(@node), method: :post do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input_field :user, label: "Users", collection: @users, as: :check_boxes, checked: @node.user_tags %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
這不起作用,因爲@node
是零 - 即它沒有通過。我無法從我的_footer
部分傳遞該變量,所以我希望能夠在模態的原始執行中傳遞它。
我如何做到這一點?或者我如何以另一種方式做到這一點?
編輯1
要添加更多的上下文,即調用引導模態初始鏈路實際上是另一部分是具有node
一個局部變量傳遞給它也。一個被稱爲是這樣的:
<%=渲染部分:「共享/箱」,當地人:{節點:節點}%>
但我仍然需要繼續模態的執行僅切換之後被解僱首先點擊鏈接shared/box
。
總結: - /shared/box
部分有原始鏈接,引發BS模式。 - /shared/footer' contains a render of another partial
tag_users_modal . -
/shared/tag_users_modal contains the modal, but I need the
@node object passed to it and the
add_tagged_user_node_path`工作。
現在它沒有通過,因爲我不能想出一個辦法來獲得原來的node: node
到鏈中的第三部分。
我明白,但這不是問題。發生了什麼是我的部分存儲在'shared'目錄中,並且該部分是從'shared'目錄中的另一個部分調用的。該部分被調用了一個局部變量'node:node',但是因爲我正在將執行傳遞給只在上面的鏈接被點擊時觸發的模式,所以我無法將該'node:node'傳遞給部分在點擊鏈接之後呈現彈出/模式。我希望這更清楚。如果這是標準控制器中的標準視圖,則您的建議可行。但是它不是:( – marcamillion 2015-03-13 07:38:17
我增加了更多的細節,所以你可以更清楚地知道我想實現的目標。 – marcamillion 2015-03-13 07:43:16
首先,從你的partials中刪除所有的實例變量,然後使用局部變量,這只是一般性的建議。在你定義它的時候,問題是你根本沒有想要使用的變量,沒有「解決方案」,你必須重新填充變量,然後才能使用變量。在鏈接中有一些參數,當鏈接被點擊並且控制器動作被調用時,它將幫助你重新找到'node'。 – Humza 2015-03-13 08:05:13