views:

18

answers:

0

Hello,

I have two models; "entry" and "imageblock". Entry contains some text, and imageblock has a photo attachment and some text about the photo. Entry can have many imageblocks and imageblock belongs to entry.

I want to add different types of imageblocks to the entry. One has a thumbnail, another a medium pic, large pic etc. I know you can specify multiple sizes with something line the following:

has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>", :original => "400x400>" } 

However I want the user to be able to pick a different image per "type" and also to only upload one image per entry.

I have an image_type_id flag in my imageblocks model. I tried to run the following code however got a not defined error:

  if image_type_id == 1 
     has_attached_file :photo, :styles => { :original => "400x400>" } 
  elsif image_type_id == 3
    has_attached_file :photo, :styles => { :original => "100x100>" } 
  else 
    has_attached_file :photo, :styles => { :original => "200x200>" } 
  end

Error:

undefined local variable or method `image_type_id' for #<Class:0x10383c530>

Is there a way to dynamically set/override the styles parameter block when uploading an image?

I am also trying the Proc as described here http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip but not sure how to get it to work.