Lagoa Multiphysics 1.0

Posted by Ryan Baxter Wed, 21 Jul 2010 03:17:00 GMT

Robert Martin's "Twenty-Five Zeros" Keynote at RailsConf 2010

Posted by Ryan Baxter Fri, 25 Jun 2010 02:04:00 GMT

Hello MongoDB

Posted by Ryan Baxter Thu, 18 Feb 2010 04:11:00 GMT

In an effort to jump-start my creativity, I thought I’d hop on the NoSQL train and work up a little “Hello World” app using MongoDB with Sinatra and MongoMapper. In a later project I’ll be throwing Haml into the mix and working completely outside of my comfort zone. Dependencies be damned!

require 'rubygems'
require 'mongo_mapper'
require 'sinatra'

MongoMapper.connection = Mongo::Connection.new('localhost')
MongoMapper.database = 'messages'

class Message
  include MongoMapper::Document
  key :message, String
  key :ip_address, String
  timestamps!
end

get '/' do
  Message.all.map { |m|
    time = m.created_at.localtime
    "On #{ time.strftime('%m/%d/%Y') } at " \
    "#{ time.strftime('%I:%M %p')} <strong>#{ m.ip_address }</strong> said, " \
    "<strong>\"#{ m.message }\"</strong>"
  }.join "<br />"
end

get '/:message' do
  Message.create(:message => params[:message], :ip_address => @env['REMOTE_ADDR']).save
  redirect '/'
end

On 02/17/2010 at 10:13 PM 127.0.0.1 said, “Hello World!”

Older posts: 1 2 3 ... 5