require 'sinatra'
require 'config/environment'

class Overheard
  include DataMapper::Resource

  property :id, Serial
  property :body, Text
  property :created_at, DateTime
end

DataMapper.finalize
DataMapper.auto_upgrade!

get '/' do
  @overheards = Overheard.all
  erb :home
end

get '/overheards/new' do
  erb :new_overheard
end

post '/overheards' do
  overheard = Overheard.create(params["overheard"])
  redirect "/"
end

require 'sinatra'
require 'config/environment'

class Overheard
  include DataMapper::Resource

  property :id, Serial
  property :body, Text, { :required => true }
  property :created_at, DateTime
end

DataMapper.finalize
DataMapper.auto_upgrade!

get '/' do
  @overheards = Overheard.all
  erb :home
end

get '/overheards/new' do
  erb :new_overheard
end

post '/overheards' do
  overheard = Overheard.create(params["overheard"])
  if overheard.saved?
    redirect "/"
  else
    erb :new_overheard
  end
end

Add validation that Overheard must have a body
Add validation that Overheard must have a body

Here we're doing two things:
1. We're creating a validation that will prevent an overheard from being
   created if a body isn't provided
2. We're only redirecting if the creation was successful; otherwise we
   re-render the new overheard form
