Skip to content

Instantly share code, notes, and snippets.

@tibra
Created February 8, 2011 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tibra/816256 to your computer and use it in GitHub Desktop.
Save tibra/816256 to your computer and use it in GitHub Desktop.
Trying to retrieve :shape in model
class UploadsController < ApplicationController
def create
...
@upload.shape = "photo"
...
if @upload.save
...
end
class Upload < ActiveRecord::Base
has_attached_file :attachment,
:path => ":class/:parent_type/:id/:style.:extension",
:styles => lambda { |a|
# Don't apply assign_shape (= do not set style) when content_type == picture
if ['image/jpeg','image/png','image/gif'].include?(a.instance_read(:content_type))
a.instance.assign_shape( What to pass in here to get :shape value I've set in @upload.shape] )
else
{}
end
}
def assign_shape(shape)
case shape
when "gallery"
{ :preview => "700x467>", :mid => "350x234>", :small => "230x153>" , :tiny => "100x67>" }
when "photo"
{ :preview => "270x346>", :small => "100x128>" , :tiny => "78x100>" }
when "logo"
{ :preview => "250x250>", :small => "150x150>" , :tiny => "70x70>" }
when "sponsor"
{ :preview => "250x250>", :super => "728x90>" , :halfsize => "234x60!" }
when "generic_file"
{}
else
{ :standard => "500x500>", :small => "250x250>", :tiny => "125x125>" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment