Skip to content

Instantly share code, notes, and snippets.

@jakehow
Created March 9, 2009 22:27
Show Gist options
  • Save jakehow/76525 to your computer and use it in GitHub Desktop.
Save jakehow/76525 to your computer and use it in GitHub Desktop.
>> s = Statement.new
=> {"updated_at"=>nil, "couchrest-type"=>"Statement", "created_at"=>nil}
>> s.create_attachment(:name => 'test.txt', :content_type => 'text/plain', :file => File.open('test.txt'))
=> {"content-type"=>"text/plain", "data"=>"dGVzdAo="}
>> s.save
=> nil
>> s['_attachments']['test.txt']
=> {"content-type"=>"text/plain", "data"=>"ZEdWemRBbz0="}
>> s['_attachments']['test.txt']['content-type']
=> "text/plain"
>> s.id
=> "34f4cbdc4b304649366645fa692455ab"
>> x = Statement.get(s.id)
=> {"updated_at"=>Mon Mar 09 18:23:52 -0400 2009, "_rev"=>"961074468", "_id"=>"34f4cbdc4b304649366645fa692455ab", "couchrest-type"=>"Statement", "_attachments"=>{"test.txt"=>{"content_type"=>"application/octet-stream", "stub"=>true, "length"=>8}}, "created_at"=>Mon Mar 09 18:23:52 -0400 2009}
>> x['_attachments']['test.txt']
=> {"content_type"=>"application/octet-stream", "stub"=>true, "length"=>8}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment