Ruby on Rails +回形针 + Facebox:图像加载为文本而不是图像
当我使用绝对 URL 加载图像时,会发生以下情况: http://dl.dropbox.com/u/331982/Help/Screen%20shot%202011-08-31%20at%2011.17.44%20AM%20copy.png
是什么原因图像不被渲染为图像?
是Facebox的问题吗?
这就是我制作图像链接的方式:
<a href="images/stairs.jpg" rel="facebox">text</a>
就像在网站上一样 http://defunkt.io/facebox/
下载方法:
def download
head(:not_found) and return if (media = Media.find_by_id(params[:id])).nil?
path = media.document.path(params[:style])
head(:bad_request) and return unless File.exist?(path) && params[:format].to_s == File.extname(path).gsub(/^\.+/, '')
send_file_options = { :disposition => 'inline', :type => media.document.content_type }
send_file_options = { :disposition => 'inline' } if File.extname(path) == ".swf" && media.document_content_type == "application/x-shockwave-flash"
case SEND_FILE_METHOD
when :apache then send_file_options[:x_sendfile] = true
when :nginx then head(:x_accel_redirect => path.gsub(Rails.root, ''), :content_type => send_file_options[:type]) and return
end
send_file(path, send_file_options)
end
here is what happens when I load an image with an absolute URL:
http://dl.dropbox.com/u/331982/Help/Screen%20shot%202011-08-31%20at%2011.17.44%20AM%20copy.png
What is causing the image not to be rendered as an image?
Is it an issue with Facebox?
This is how I made the image link:
<a href="images/stairs.jpg" rel="facebox">text</a>
Just like on the website http://defunkt.io/facebox/
The download method:
def download
head(:not_found) and return if (media = Media.find_by_id(params[:id])).nil?
path = media.document.path(params[:style])
head(:bad_request) and return unless File.exist?(path) && params[:format].to_s == File.extname(path).gsub(/^\.+/, '')
send_file_options = { :disposition => 'inline', :type => media.document.content_type }
send_file_options = { :disposition => 'inline' } if File.extname(path) == ".swf" && media.document_content_type == "application/x-shockwave-flash"
case SEND_FILE_METHOD
when :apache then send_file_options[:x_sendfile] = true
when :nginx then head(:x_accel_redirect => path.gsub(Rails.root, ''), :content_type => send_file_options[:type]) and return
end
send_file(path, send_file_options)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来像 MIME 类型错误,您将其返回为 HTML 或解释为 HTML 的内容。如果您使用
send_file
,请务必设置您的响应 MIME 类型。这是send_file
的:type
选项。This looks like a MIME type error, where you're returning it as HTML or something interpreted as HTML. If you're using
send_file
, be sure to set your response MIME type. This is the:type
option forsend_file
.您需要使用以下补丁来修补facebox.js。
https://github.com/ipavelek/facebox/commit/e4a0101596cd269f8337920564c8d33e193e8cbe
Facebox 不处理 Rails 附加到图像的 URL 查询参数。
You need to patch facebox.js with the following patch.
https://github.com/ipavelek/facebox/commit/e4a0101596cd269f8337920564c8d33e193e8cbe
Facebox doesn't handle the URL query param that rails appends to images.