Anibal R.
Anibal R.

Reputation: 808

How do I rename a file upload with paperclip?

I am trying to rename the images that I upload with paperclip, on the data values ​​placed on inputs. Here is my code:

class Deposito < ActiveRecord::Base
  attr_accessible :banco, :fecha, :monto, :rafaga, :cheque

  has_attached_file :cheque, :styles => { :medium => "800x600>", :thumb => "100x100>" }, 
                :url  => "/assets/depositos/:id/:style/:basename.:extension",
                :path => ":rails_root/public/assets/depositos/:id/:style/:basename.:extension"

  validates_attachment_content_type :cheque, :content_type => ['image/jpeg', 'image/png', 'image/gif']

end

I need the name of the image is the values ​​of bank, date, burst, amount.

Thank you.

Upvotes: 1

Views: 882

Answers (1)

TM.
TM.

Reputation: 3741

Try out this:

class Deposito < ActiveRecord::Base
  attr_accessible :banco, :fecha, :monto, :rafaga, :cheque

  has_attached_file :cheque, :styles => {:medium => "800x600>", :thumb => "100x100>"},
    :url => "/assets/depositos/:id/:style/:normalize_basename.:extension",
    :path => ":rails_root/public/assets/depositos/:id/:style/:normalize_basename.:extension"

  validates_attachment_content_type :cheque, :content_type => ['image/jpeg', 'image/png', 'image/gif']

  Paperclip.interpolates :normalize_basename do |attachment, style|
    attachment.instance.normalize_basename
  end


  def normalize_basename
    # put your filename here
  end
end

Upvotes: 2

Related Questions