Created
February 8, 2011 10:44
-
-
Save tibra/816256 to your computer and use it in GitHub Desktop.
Trying to retrieve :shape in model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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