ruby-on-rails - Rails Paperclip - 获取不同尺寸图像的路径

标签 ruby-on-rails paperclip

我使用回形针来存储两种不同尺寸的图像(除了原始图像之外)。这是类(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/

相关文章:

ruby-on-rails - 将日期时间更改为月、日、年

ruby-on-rails - 未知操作 没有操作响应显示

ruby-on-rails - 回形针验证导致Rails 3错误

ruby-on-rails - Rails 回形针 `is not recognized by the ' 识别'命令`

ruby-on-rails - 错误 : `No handler found` with Base64 for Paperclip 5. 2

ruby-on-rails - ActiveRecord 加入 ID 数组

ruby-on-rails - 使用 poolparty 和 Chef 服务器在 EC2 上部署

ruby-on-rails - 从数组中提取单个案例

ruby-on-rails - 带有回形针 Docx content_type 的 Rails 将作为应用程序/zip 回来

ruby-on-rails - Ruby on rails 在上传到 s3 时出现 Paperclip 问题