lundi 16 mars 2015

Using model attribute as :filename when using paperclip gem

I'm getting an error when attempting to change the :filename of my paperclip attachment to equal an attribute on the class I'm attaching the paperclip file to.


When I use "#{self.company_name}" it errors out. Apparently in this scope, "self" is not Company. When I wrote this line I assumed that self is the instance of Company that I'm uploading this attachment to. Any idea how I can fix this? The Paperclip docs say to use ":filename" but I'd like to use the value of Company.company_name instead.



class Company < ActiveRecord::Base
include AliasAttrs

has_attached_file :company_logo, {

:storage => :ftp,

:path => "/logos/#{self.company_name}",

:url => FTP_CONFIG[:access_host]+"logos/:filename",

:ftp_servers => [
{
:host => FTP_CONFIG[:host],
:user => FTP_CONFIG[:user],
:password => FTP_CONFIG[:pass],
:port => 21 # optional, 21 by default
}
]
}
end

Aucun commentaire:

Enregistrer un commentaire