【问题标题】:Rails why is this image not rendering (Rmagick, Heroku)Rails 为什么这个图像不渲染(Rmagick,Heroku)
【发布时间】:2013-06-06 10:44:50
【问题描述】:

我的观点如下:

<%= image_tag (url_for(:controller => 'app_images', :action => 'picture')) %>

对应的控制器动作为:

  def picture
    image = AppImage.create(:path => ("portrait3.jpeg"))
    image.set_file_from_path
    portrait = Magick::Image::from_blob(image.file)[0]
    send_data portrait.to_blob, :type => "image/jpeg", :disposition => "inline" 
  end

而set_file_from_path的模型方法是

  def set_file_from_path
    image = Magick::Image::from_blob(open(self.path).read)[0]
    if image.rows > 400
      resized = image.scale(400 * image.columns / image.rows, 400)
    else
      resized = image
    end
    self.file = resized.to_blob
  end

由于某种原因,此 image_tag 不在 Heroku 中呈现,而是在本地呈现,并且我的 app/assets/images 文件夹中有“portrait3.jpeg”文件。

编辑:我意识到我在 heroku 中使用了 create 而没有实际连接到 S3 或其他任何东西,这可能不起作用,因为我相信 heroku 不允许在其服务器上存储数据库。换了新的还是不行。

【问题讨论】:

    标签: ruby-on-rails heroku rmagick


    【解决方案1】:

    所以我做了一些愚蠢的事情。首先,我忘了在控制器中要求 RMagick,其次我需要执行 heroku run rake db:migrate。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-24
      • 1970-01-01
      • 2020-08-27
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多