我使用回形针来存储两种不同尺寸的图像(除了原始图像之外)。这是类(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
我可以很容易地获取原始文件的路径:
PassTemplate.find(1).logo.path
这给了我:
"<full_system_path>/public/system/pass_templates/logos/000/000/040/original/dog_closeup.jpg"
是否有一个快速且简单的访问器来获取其他尺寸的路径? 我可以自己编写,但我认为会有一种更简单的方法来获取它。
理想情况下我能够拥有这样的东西:
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)
关于ruby-on-rails - Rails Paperclip - 获取不同尺寸图像的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15231170/