Skip to content

Instantly share code, notes, and snippets.

View jonmagic's full-sized avatar

Jonathan Hoyt jonmagic

View GitHub Profile
class SongsController < ApplicationController
def index
@songs = Song.all(:destroyed_at => nil)
@totals = load_totals(@songs)
end
def new
@song = Song.new
render :layout => false
class Song
include MongoMapper::Document
plugin Grip
attachment :mp3
key :title, String
key :artist, String
key :album, String
key :genre, String
s = Song.all[2]
=> #<Song duration: 35.19925, artist: nil, mp3_id: ObjectID('4b98007de5947c54f7000010'), title: "LCT-PO-MATAHARI 042009.mp3", destroyed_at: nil, _id: ObjectID('4b98007de5947c54f700000f'), album: nil, genre: nil, mp3_name: "LCT-PO-MATAHARI 042009.mp3", mp3_type: "audio/mpeg", mp3_size: 577430>
>> s.mp3_id
=> ObjectID4b98007de5947c54f7000010
>> s.mp3_id.to_s
=> "4b98007de5947c54f7000010"
curl http://localhost:3333/gridfs/4b98007de5947c54f7000010
returns the following errors
NoMethodError at /gridfs/4b98007de5947c54f7000010
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[]
Ruby /Library/Ruby/Gems/1.8/gems/mongo-0.19.1/lib/../lib/mongo/gridfs/grid_io.rb: in read_all, line 208
Web GET localhost/gridfs/4b98007de5947c54f7000010
Jump to:
GETPOSTCookiesENV
Traceback (innermost first)
/Library/Ruby/Gems/1.8/gems/mongo-0.19.1/lib/../lib/mongo/gridfs/grid_io.rb: in read_all
# install required packages for building
sudo apt-get install build-essential libssl-dev libreadline5-dev
# download and install ruby
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p248.tar.gz
tar zxvf ruby-1.8.7-p248.tar.gz
cd ruby-1.8.7-p248
./configure
make
sudo make install
require "test_helper"
require File.expand_path(File.dirname(__FILE__) + '/../lib/grip')
class Foo
include MongoMapper::Document
include Grip
has_grid_attachment :image
has_grid_attachment :pdf
db.ticket_items.find()
error: {"_id" : ObjectId( "4b100a29be36154d4ec50047") , "$err" : "Invalid BSONObj spec size"}
require 'pp'
require 'rubygems'
require 'mongo_mapper'
require 'benchmark'
MongoMapper.database = 'testing'
class Foo
include MongoMapper::Document
# get some fruit!
orange = { "name": "Orange", "owners": [{ "Jon": 2 }, { "Steve": 5 }] }
apple = { "name": "Apple", "owners": [{ "Jon": 4 }, { "Bill": 2 }] }
pear = { "name": "Pear", "owners": [{ "Jon": 1 }, { "Tom": 3 }] }
# save the fruit
db.foo.save(orange)
db.foo.save(apple)
db.foo.save(pear)
# get some fruit!
orange = { "name": "Orange", "owners": [{ "Jon": 2 }, { "Steve": 5 }] }
apple = { "name": "Apple", "owners": [{ "Jon": 4 }, { "Bill": 2 }] }
pear = { "name": "Pear", "owners": [{ "Jon": 1 }, { "Tom": 3 }] }
# save the fruit
db.foo.save(orange)
db.foo.save(apple)
db.foo.save(pear)