Squadrons
Squadrons

Reputation: 2567

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"

Upvotes: 2

Views: 824

Answers (1)

Ilia Khokhriakov
Ilia Khokhriakov

Reputation: 3687

Pass style as an argument to path method:

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

Upvotes: 5

Related Questions