Skip to content

Instantly share code, notes, and snippets.

@houen
Created July 11, 2011 16:38
Show Gist options
  • Save houen/1076237 to your computer and use it in GitHub Desktop.
Save houen/1076237 to your computer and use it in GitHub Desktop.
dsfgdsfg
Loading development environment (Rails 3.0.7)
irb: warn: can't alias exit from irb_exit.
ruby-1.9.2-p180 :001 > inst = ImageUploader.new
=>
ruby-1.9.2-p180 :002 > inst.recreate_versions!
NoMethodError: undefined method `read' for nil:NilClass
from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/carrierwave-0.5.5/lib/carrierwave/uploader/cache.rb:73:in `cache_stored_file!'
from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/carrierwave-0.5.5/lib/carrierwave/uploader/versions.rb:174:in `recreate_versions!'
from (irb):2
from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
ruby-1.9.2-p180 :003 >
@houen
Copy link
Author

houen commented Sep 19, 2011

Not as far as I know, but the reason is as hamzakc writes. This means you can work around it quiite easily with a function usch as this:

class UserWithImage
def recreate_images
self.image.recreate_versions! if self.image.present?
end

@houen
Copy link
Author

houen commented Sep 19, 2011

Of course this means you have to recreate the image versions on a singular level, instead of the fire-and-forget above, but it works...

@seethroughdev
Copy link

Thanks for the response houen...

And please forgive me. I'm a bit new to all of this. Where should I add that function to run a one-off of recreate_versions! I seem to get the method error every way I try.

Thanks again...

@hamzakc
Copy link

hamzakc commented Sep 20, 2011

You can add it to the model that has the associated image. However if you want to do it as a one off, you could always use script/console (script/rails c in Rails 3). I personally made a rake task that did this as opposed to adding it to the model.

@seethroughdev
Copy link

Hi hamzakc...

Thanks so much for this. Its perfect info. I will use it tonight.

Take care guys,

Adam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment