Ruby on Rails +回形针 + Facebox:图像加载为文本而不是图像

发布于 2024-12-02 05:24:18 字数 1365 浏览 4 评论 0原文

当我使用绝对 URL 加载图像时,会发生以下情况: http://dl.dropbox.com/u/331982/Help/Scr​​een%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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苄①跕圉湢 2024-12-09 05:24:18

这看起来像 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 for send_file.

倾城泪 2024-12-09 05:24:18

您需要使用以下补丁来修补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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文