#8 √ duplicate
Chris Olsen

Allow for easy setting of default urls

Reported by Chris Olsen | April 13th, 2008 @ 04:26 PM

*** Update

I didn't realize someone posted this just a couple of days ago.

It would be nice to be able to set some global default values for the url and path parameters instead of having to set them each time for each of the models.

I know there are hardcoded default values, but I am sure many people will not want to use them.

Even if you allow some ENV values to be set, that would be great.

Doing the below on my current project now allows me to have DRY has has_attached_file method calls within my models

ex.

module Paperclip

  1. The Attachment class manages the files for a given attachment. It saves when the model saves,
  2. deletes when the model is destroyed, and processes the file upon assignment.

class Attachment

def self.default_options

@default_options ||= {

:url => ENV['paperclip_url'] ||= "/uploads/:class/:style/:id_:basename.:extension",

:path => ENV['paperclip_path'] ||=":rails_root/public/uploads/:class/:style/:id_:basename.:extension",

:styles => {},

:default_url => ENV['paperclip_default_url'] ||="/uploads/:class/:style/missing.png",

:default_style => :original,

:validations => [],

:storage => :filesystem

}

end

Thanks Jon

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket