Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.1

Why do I get "undefined method `strip!' for #" when using MiniMagick?


I put the strip method in the CarrierWave initializer:

 def strip
   manipulate! do |img|
     img.strip!
     img = yield(img) if block_given?
     img
   end
 end

and call on the uploader:

 version :thumb do
   process :resize_to_fit => [180, nil]
   process :quality => 70
   process :strip   
 end

Now Rails spits out this error:

undefined method `strip!' for #


Solution

  • Undefined #strip Method

    You define your method like so:

    def strip
      manipulate! do |img|
        img.strip!
        img = yield(img) if block_given?
        img
      end
    end
    

    but it's unclear from your code sample whether img actually has a #strip or #strip! method. The error is complaining about a bang method being undefined, so try img.strip instead.

    Introspection

    If that doesn't work, you may want to insert some debugging code in the method so that you can see what img really is, and what methods it actually supports. For example:

      manipulate! do |img|
        puts img.class
        puts img.methods.sort
        img.strip
        img = yield(img) if block_given?
        img
      end
    

    Hope that helps.

    See Also

    CarrierWave::MiniMagick