Created
November 9, 2009 19:11
-
-
Save travisbell/230180 to your computer and use it in GitHub Desktop.
This file contains 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 '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 | |
array = Array.new | |
things.each do |t| | |
array << "#{t.name}<br />" | |
end | |
# Output array as a string | |
# Usually I'd use a view but this is just a crude example | |
array | |
# 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