Rails Rendering从索引页以Bootstrap模式显示
Rails Rendering Show in Bootstrap Modal from index page
我正试图通过Bootstrap Modal从照片索引页面渲染"show"。如果我直接使用显示页面(..'views'photos'show.html.erb)
而不通过引导模式渲染,则预期的照片(使用carrierwave未加载)会正确显示。
但问题是,当我尝试用_show.html.erb.
渲染时,照片不会显示。然而,即使_show.html.erb.
中有任何可用的硬编码文本,后备图像也会显示。以下是片段;
views'photos'_show.html.erb
`<% if @photo.image? %>
<%= image_tag @photo.image.url(:thumb2) %> #this is the intended photo
<% else %>
<%= image_tag("fallback/default.png") %>
<% end %>`
Photos_controller.rb
`def show
@photo = Photo.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @photo }
end
end`
`views'photos'index.html.erb` for Bootstrap modal
<div class =”..”>
<% if photo.image?
<%# Added Bootstrap data modal attribute %>
<%= link_to (image_tag photo.image.url(:thumb)), '#showModal', 'data-toggle' => 'modal' %>
<div class="modal fade" id="showModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Showing photo</h4>
</div>
<div class="modal-body">
<%= render 'show' %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
photo.js
$("#showModal").click(function(){
$("#show").modal();
});
已解决:不是javascript问题ruby。
http://api.rubyonrails.org/classes/ActionView/PartialRenderer.html
在索引页中,我更改了<%=将"show"%>渲染为<%=render:partial=>"show",:locals=>{:photo=>photo}%>然后将show.html.erb中的@photo更改为photo,使其成为索引页中的局部变量。
相关文章:
- 如何动态更改React Bootstrap模式的内容
- 在Bootstrap模式窗口中打开远程内容
- bootstrap模式在windowsvista上的IE8上运行极其缓慢
- Jquery UI don'使用bootstrap 3模式时效果不佳
- 在ajax回调(safari)中调用bootstrap模式显示
- 一旦Bootstrap模式选项已经存在,请更改该选项
- 当内部的任何模式关闭时,Bootstrap模式关闭
- bootstrap日期选择器轨道无法通过带有bootstrap模式的simple_form工作
- Bootstrap 3模式从水平到内联的变化-调整大小很尴尬
- Twtitter Bootstrap模式显示事件多次触发
- 确定哪个按钮打开了Bootstrap 3模式
- 如何使用 javascript 隐藏 Bootstrap 模式
- Bootstrap模式加载远程内容,生成2个请求
- c#asp.net如何使用bootstrap模式将视频源文件名添加到不同的媒体类型中
- bootstrap模式中的Twitter共享按钮在firefox上不起作用
- Bootstrap 3模式并不总是激活ajax代码
- PHP和Bootstrap模式变量
- Bootstrap 3模式-从底部滑入并粘牢
- 如何清理(销毁)Twitter Bootstrap 3.2模式表单内容
- 如何在AngularJS Bootstrap模式中从AJAX调用加载JSON数据