我有for循环,我在循环的每次迭代中调用partial:
<% applications.each do |application| %>
<td>
<%= render :partial => "layouts/form", :locals => {:@application => application} %>
</td>
<% end %>
现在,在部分内部,我有一个按钮,按下时会显示一个模态:
<button type="button" class="button-custom btn-primary" data-toggle="modal" data-target="#form-modal"> <%= "#{button_text}" %> </button>
<div id="form-modal" class="modal fade modal-form" role="dialog" tabindex='-1'>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<td> <%= "#{@application.name}" %> </td>
现在的问题是@application.name
总是引用for循环中第一个应用程序的值。它没有得到与循环的相应迭代相对应的值。
答案 0 :(得分:1)
从@
变量中删除application
符号。
<%= render :partial => "layouts/form", :locals => {:application => application} %>
....
<td> <%= application.name %> </td>
您应该为每个应用程序生成唯一的模态ID。
data-target="#form-modal-<%= application.id %>"
<div id="form-modal-<%= application.id %>"