Skip to content

Instantly share code, notes, and snippets.

@travisbell
Created November 9, 2009 19:18
Show Gist options
  • Save travisbell/230188 to your computer and use it in GitHub Desktop.
Save travisbell/230188 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'mongo_mapper'
# =======================================================================================================
# DB SETUP
MongoMapper.database = 'mytest'
class Thing
include MongoMapper::Document
key :name, String
end
# =======================================================================================================
# ROUTES
get '/' do
things = Thing.find(:all)
# Works
test = ''
things.each do |t|
test += "#{t.name}<br />"
end
# Output things
# Usually I'd use a view but this is just a crude example
test
# Doesn't work, gives _bytesize error
# things.each do |t|
# t.name
# end
end
get '/add' do
Thing.create(:name => "Test #{Time.now}")
redirect '/'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment