This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SongsController < ApplicationController | |
| def index | |
| @songs = Song.all(:destroyed_at => nil) | |
| @totals = load_totals(@songs) | |
| end | |
| def new | |
| @song = Song.new | |
| render :layout => false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Song | |
| include MongoMapper::Document | |
| plugin Grip | |
| attachment :mp3 | |
| key :title, String | |
| key :artist, String | |
| key :album, String | |
| key :genre, String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.ticket_items.find() | |
| error: {"_id" : ObjectId( "4b100a29be36154d4ec50047") , "$err" : "Invalid BSONObj spec size"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pp' | |
| require 'rubygems' | |
| require 'mongo_mapper' | |
| require 'benchmark' | |
| MongoMapper.database = 'testing' | |
| class Foo | |
| include MongoMapper::Document | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |