Skip to content

Instantly share code, notes, and snippets.

@Amitesh
Created August 1, 2011 11:28
Show Gist options
  • Select an option

  • Save Amitesh/1117971 to your computer and use it in GitHub Desktop.

Select an option

Save Amitesh/1117971 to your computer and use it in GitHub Desktop.
Upload file from ruby on rails program with paperclip gem
# MyModel Model
class MyModel < ActiveRecord::Base
has_attached_file :my_image,
:styles => { :small_thumb => "50x50",
:medium_thumb => "100x100"
},
:default_url => "/images/missing/prints/:style.png"
end
# Ruby code to upload/push the image into MyModel Model and create the images of different sizes
my_model_obj = MyModel.new
my_model_obj.my_image = File.open('file/path')
my_model_obj.save!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment