我需要data-toggle =" modal"中的选定值。我得到了值但无法分配给ruby变量,所以我无法获取我想要的数据。
<%= form_for(:repair, :url => { :controller => "owners", :action => 'property_repairs',:owner_id => current_user.owner.slug }) do |f| %>
<%= collection_select(:property,:id,Property.where(owner_id: @owner.id, property_active: true).order(created_at: :desc),:id,:property_address,{:prompt => 'please select the property for Repair'},{class: "form-control"}) %>
<%= f.submit 'Repair', :class => 'btn btn-primary' %>
<% @repair = Repair.where(:owner_id => @owner.id)%>
<%end%>
<% @repair = Repair.where(:owner_id => @owner.id)%>
<% @repair.each do |repair| %>
<%property = Property.find(repair.property_id)%>
<tr>
<td class="input-group-addon "> <%=property.property_address %></td>
<td class="input-group-addon"> <%= repair.category %></td>
<td class="input-group-addon"> <%= repair.start_date %></td>
<td class="input-group-addon"> <%= repair.end_date%></td>
<td class="input-group-addon"> <%= repair.cost %></td>
<div id="pop">
<td button type="button" data-id = "<%=repair.id%>" class="input-group-addon" data-toggle="modal" data-target="#myPop">
<h class="text-primary text-left">View</h>
</td>
</tr>
<%end%>
我给了&#34;模态&#34;在同一个html.erb中。在这里,我想要我选择的数据
<div class="modal fade" id="myPop" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div class="modal-body">
<div>
<input id = "myPop" value ="">
</div>
</div>
</div>
</div>
在脚本中我获得了价值,但无法在Modal中分配,因为它有输入值
<script>
$(document).on("click", ".input-group-addon", function () {
var myBookId = $(this).data('id');
var value = $(".modal-body #myPop").val( myBookId );
});
</script>
提前致谢
答案 0 :(得分:0)
如果你想在DB中存储该值,你应该使用AJAX来调用ruby方法。否则,您将无法将javascript-var分配给ruby-var。
使用以下命令查看link_to或form_for:remote =&gt;真实选择: