Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道&x2B;回形针-仅限商店调整大小的图像_Ruby On Rails_Paperclip - Fatal编程技术网

Ruby on rails 轨道&x2B;回形针-仅限商店调整大小的图像

Ruby on rails 轨道&x2B;回形针-仅限商店调整大小的图像,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我的模型看起来像: class Photo < ApplicationRecord has_attached_file :image, :styles => { :small => "50x50#" }, :default_style => :small validates_attachment :image,

我的模型看起来像:

class Photo < ApplicationRecord
  has_attached_file :image, 
                    :styles => { :small => "50x50#" },
                    :default_style => :small                   

  validates_attachment :image,
                       content_type: { content_type: ["image/jpeg",   
                                      "image/gif", "image/png"] }
end
班级照片{:small=>“50x50#”},
:default_style=>:small
验证_附件:图像,
内容类型:{content类型:[“image/jpeg”,
“image/gif”、“image/png”]}
结束

RAILS存储图像两次:原始大小和
:small
中定义的大小。我只想存储大小调整后的图像。

我相信您可以简单地为:original定义一种样式,让回形针将原稿替换为该尺寸

:styles => { :original => '300x168>', :cropped_thumb => {:geometry => "50x50#", :jcrop => true}, ...}
谢谢你,puneet18

此模型可以完成以下任务:

class Photo < ApplicationRecord
  has_attached_file :image, 
                    :styles => { :original => "50x50#" },
                    :default_style => :original

  validates_attachment :image,
                       content_type: { content_type: ["image/jpeg", "image/gif",
                                       "image/png"] }
end
班级照片{:original=>“50x50#”},
:default_style=>:原始
验证_附件:图像,
内容类型:{content类型:[“image/jpeg”,“image/gif”,
“image/png”]}
结束