【问题标题】:Ruby on Rails / Paperclip Gem: Does not resize images, seems to only save 'original' imageRuby on Rails / Paperclip Gem:不调整图像大小,似乎只保存“原始”图像
【发布时间】:2011-02-14 21:20:36
【问题描述】:

我已经安装了回形针 gem。它正在其他地方使用,所以我知道它正在工作。

我有我的模型,

class Slide < ActiveRecord::Base
has_attached_file :image, :style => {
  :large => "1400x786!",
  :medium => "128x128>",
  :small => "105x90!"
}
end

我创建了我的专栏

class AddImageToSlides < ActiveRecord::Migration
  def self.up
    add_column :slides, :image_file_name,       :string
    add_column :slides, :image_content_type,    :string
    add_column :slides, :image_file_size,       :interger
    add_column :slides, :image_updated_at,      :datetime
  end

  def self.down
    remove_column :slides, :image_file_name
    remove_column :slides, :image_content_type
    remove_column :slides, :image_file_size
    remove_column :slides, :image_updated_at
  end
end

我做了耙子,

rake db:migrate

我的表单中有“{ :multipart => true }”

<%= form_for(@slide, :class=>"slidesForm", :html => { :multipart => true }) do |f| %>

我正试图像这样提取图像信息,

<div class="slidesPreview" style="background:url('<%= @slide.image.url(:large) %>') top left no-repeat;">

只有当我使用“@slide.image.url”时它才会起作用,但它只显示原始照片。

我查看了 public/system/images/,它似乎只保存原始/而不是大/、中/或小/。我检查了错误日志,什么也没有。

我刚开始学习 RoR,所以请原谅我的无知。

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 paperclip gem


    【解决方案1】:

    这是:style**s** =&gt; { ... },而不是:style =&gt; ...(附加的s!)

    【讨论】:

      【解决方案2】:

      你只是忘了指定photo @slide.image.url(:small), @slide.image.url(:medium), @slide.image.url(:large)的大小

      【讨论】:

      • 请完整阅读问题。 OP 确实使用了 .url(:size) 符号。
      【解决方案3】:

      我尝试了以下方式。它工作正常。 希望对大家有所帮助。

      1.在 Gemfile 中添加以下 gem:

      gem "ImageResize", "~> 0.0.5"
      

      2.运行包

      3.在控制器功能中使用:

      require 'rubygems'
      require 'ImageResize'
      
      #input_image_filename, output_image_filename, max_width, max_height
      Image.resize('big.jpg', 'small.jpg', 40, 40)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-27
        • 2012-01-21
        • 1970-01-01
        相关资源
        最近更新 更多