Browse files

Make sure Paperclip doesn't raise an exception when using a numeric s…

…tyle name
  • Loading branch information...
1 parent f6e01b6 commit 8edccdce415e0d556fc367e120f8b042cbe07bdd @webmat committed Mar 12, 2012
Showing with 2 additions and 2 deletions.
  1. +1 −1 lib/paperclip/interpolations.rb
  2. +1 −1 lib/paperclip/storage/s3.rb
@@ -93,7 +93,7 @@ def basename attachment, style_name
# If the style has a format defined, it will return the format instead
# of the actual extension.
def extension attachment, style_name
- ((style = attachment.styles[style_name.to_sym]) && style[:format]) ||
+ ((style = attachment.styles[style_name.to_s.to_sym]) && style[:format]) ||
File.extname(attachment.original_filename).gsub(/^\.+/, "")
@@ -95,7 +95,7 @@ def self.extended base
@s3_permissions = set_permissions(@options[:s3_permissions])
@s3_protocol = @options[:s3_protocol] || do |style, attachment|
- permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
+ permission = (@s3_permissions[style.to_s.to_sym] || @s3_permissions[:default])
permission =, style) if permission.is_a?(Proc)
(permission == :public_read) ? 'http' : 'https'

3 comments on commit 8edccdc

Thanks for finding and fixing this Mathieu. I agree, this should be further upstream because these style args are passed around all over the place. My first step is I'm gonna put a failing test on this to recreate the error, then we can refactor to put this higher up.

Also just as an aside, "style" in s3.rb should be "style_name". That's not your bad, Mat, just me thinking out loud about this code. I might do a quick run-through and just make sure this concept is named consistently throughout the codebase.


webmat replied Mar 16, 2012


Please sign in to comment.