我正在构建我的索引html页面,我想为我的每个元素(在本例中为餐馆)提供一个模式,其中包含更多餐厅详细信息。
这是我的代码:
<div class="container text-centered">
<h1>Welcome to La Cuillère</h1>
<h2>Restaurants you can go to</h2>
<ul>
<% @restaurants.each do |r| %>
<li>
<%= link_to r.name, {"data-toggle" => "modal", "data-target" => "#restaurant_modal_#{r.id}"} %>
<%= render "restaurant_modal", restaurant: r %>
</li>
<% end %>
</ul>
<%= link_to 'Add a new restaurant', new_restaurant_path, class: 'btn btn-danger' %>
</div>
然后有一个部分(restaurant_modal.htlm.erb)里面有我的模态代码:
<div class="modal fade" id="restaurant_modal_<%= restaurant.id %>">
<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">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</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><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
请你帮我,告诉我这段代码有什么问题。
答案 0 :(得分:0)
<%= link_to r.name, "#", "data-toggle" => "modal", "data-target" => "#restaurant_modal_#{r.id}" %>
答案 1 :(得分:-1)
链接一定不能有href。尝试使用remote:true或删除链接href。
为远程选项阅读此内容:Javascript with rails