当我使用带有图像magick图像的send_data时,Rails 4抛出图像有错误

时间:2015-12-16 12:40:19

标签: ruby-on-rails ruby imagemagick

我在Rails中使用send_data方法发送图像时出现问题。 我有一个带有辅助方法的控制器,可以将图像数据发送到图像标签

class HomeController < ApplicationController

 helper_method :img


 def index

 end

 def img
   image.resize '1600x900'
   image.rotate '180'

   File.open(image.path, 'r') do |f|
     send_data f, filename: 'gift_front.jpg', :type => 'image/jpeg', :disposition => 'inline'
   end

 end
end

视图就是这一行:

<%= image_tag img, alt: 'Loading Image...', title: 'image' %>

但是当在浏览器中加载页面时,我收到此错误:

  

无法显示图像“http://localhost:3000/”,因为它包含错误。

我使用rails 4.1.2和ruby 2.2.2。 rails日志不显示任何错误。我需要从项目中的图像中获取将图像数据发送到浏览器的功能,这看起来是唯一的解决方案,但我无法找到解决此错误的方法。

0 个答案:

没有答案