amronrails
amronrails

Reputation: 100

ROR Attaching more than one file in one statement

Is there any way to shorten this code for this?? It looks so miserable

has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :image1, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :image2, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :image3, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"

Upvotes: 0

Views: 30

Answers (1)

Venu Chitta
Venu Chitta

Reputation: 300

You could do something like this:

[:logo, :image1, :image2, :image3].each do |image_symbol| 
   has_attached_file image_symbol, :styles => { :medium => "300x300>", :thumb => "100x100>" }, 
          :default_url => "/images/:style/missing.png"  
end

Hope this helps :).

Upvotes: 2

Related Questions