简体   繁体   English

Rails回形针-获取不同尺寸图像的路径

[英]Rails Paperclip - get path to different sized images

I'm using paperclip to store two different sizes of images (in addition to the original). 我正在使用回形针存储两种不同尺寸的图像(除了原始图像外)。 Here is the class: 这是课程:

class PassTemplate < ActiveRecord::Base
  self.table_name = "ba_pass_templates"
  belongs_to :organization
  has_many :passes
  has_attached_file :logo, styles: { :logo => ["29x29#", :png], :logo_2x => ["58x58#", :png] }, :dependent => :destroy

I can grab the file path for the original easily enough: 我可以很容易地获取原始文件的文件路径:

PassTemplate.find(1).logo.path

which gives me: 这给了我:

"<full_system_path>/public/system/pass_templates/logos/000/000/040/original/dog_closeup.jpg"

Is there a quick and easy accessor to grab the path for the other sizes? 是否有快速便捷的存取器来抢占其他尺寸的路径? I could write my own, but I'd assume there would be an easier way to grab it. 我可以自己写,但是我认为会有一种更简单的方法来抓取它。

Ideally I'd be able to have something like this: 理想情况下,我可以拥有这样的东西:

PassTemplate.find(1).logo.logo_path (or small_path, or whatever the path for that image was)
"<full_system_path>/public/system/pass_templates/logos/000/000/040/original/dog_closeup.jpg"

传递样式作为路径方法的参数:

PassTemplate.find(1).logo.path(:logo_2x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM