所以,我从 ckeditor 加载图像,当我渲染 html 时,它没有显示,没有出现错误,只是一个空白方块,而不是图像,我尝试了原始,html_safe,但它没有解决,我输入的文本正常显示,有人知道为什么会这样吗?
图像位于
https://user-images.githubusercontent.com/26804018/31889194-ae1084e8-b7dd-11e7-85c7-1ba09d946269.png
在我看来:
<h6><b>1. Objetivo:</b></h6>
<p><%= raw @pop.objective %></p>
我的控制器:
def show
# redirect_to :index_pdf
# @pop = Pop.friendly.find(params[:id])
@pop = Pop.find(params[:id])
pdf = render pdf: @pop.title,
:layout => false,
template: "pops/index_pdf.html.erb",
locals: {:pop => @pop},
header: {
right: 'Pág. [page] de [topage].'
}
# send_file(pdf, :filename => @pop.title+'.pdf')
# baixar automaticamente
# precisa fazer
end
我的模型:
has_attached_file :image, styles: { medium: "300x300>" }, default_url: "/images/default.png"
我通过放置一个辅助方法解决了:
def with_abs_path(htmlstring)
htmlstring.to_s.gsub(/(href|src)=(['"])/([^"']*|[^"']*)['"]/, '1=2' + 'address_of_server' + '32')
end
并调用我的 pdf 视图:
<%= raw with_abs_path(@pop.objective) %>
景色是同一个节目:
<%= raw @pop.objective %>