[英]Ruby on rails bootstrap modal window
我有帶有標題和描述的模型Post.rb
我的索引頁面。
Title 1
Title 2
Title 3
我需要在同一頁面的引導模式窗口中打開描述
index.html.erb
<ul class="content">
<%= render @posts %>
</ul>
_post.html.erb
<li>
<%= link_to post.title, '#myModal', 'data-toggle' => 'modal' %>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel"><%= post.title %></h4>
</div>
<div class="modal-body">
<%= post.description %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</li>
_post.html.erb
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content" id="modal_content">
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
創建部分_post_content.html.erb
<div class="modal-header"> <h4 class="modal-title" id="myModalLabel"><%= post.title %></h4> </div> <div class="modal-body"> <%= post.description %> </div>
2。
<%= link_to post.title, show_modal_path(post_id: post.id), remote: true %>
3。
def show_modal
@post = Post.find(params[:post_id])
end
4. show_modal.js.erb
$('#modal_content').html("<%= j render 'post_content', post: @post %>");
$("#myModal").modal('show');
show_modal
ex-創建路線 得到'show_modal /:id',到:'your_controller#show_modal',如::show_modal_path
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.