Skip to content

Instantly share code, notes, and snippets.

@chopmo
Created June 5, 2012 13:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chopmo/2874877 to your computer and use it in GitHub Desktop.
Save chopmo/2874877 to your computer and use it in GitHub Desktop.
irb(main):002:0> p = Page.new
irb(main):005:0> p.image = File.open("/Users/jtj/sample_assets/a.JPG")
irb(main):008:0> p.save
# Delay while versions are uploaded
irb(main):009:0> p.image.url
=> https://s3.amazonaws.com/dk.workingbits.dts/uploads/page/image/17/a.JPG
irb(main):011:0> p.image.url(:thumbnail)
=> "https://s3.amazonaws.com/dk.workingbits.dts/uploads/page/image/17/thumbnail_a.JPG"
@sunny0425
Copy link

For Line 2-3, I think maybe you should change to in order to auto close the file:

File.open("/Users/jtj/sample_assets/a.JPG") do |f|
p.image = f
p.save
end

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