Possible Duplicate:
Having difficulty accessing validation errors in Sinatra
I'm working through a simple Sinatra app, and I've come to the point now where I am getting "TypeError at / can't dump hash with default proc"
I am trying to validate a simple form (3 fields), and if there are any errors, show those errors to the user inputting the data.
Here's the main part of my Sinatra file (all of the pertinent info at least):
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'sinatra'
require 'rubygems'
require 'datamapper'
require 'dm-core'
require 'dm-validations'
require 'lib/authorization'
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/entries.db")
class Entry
include DataMapper::Resource
property :id, Serial
property :first_name, String, :required => true
property :last_name, String, :required => true
property :email, String, :required => true, :unique => true,
:format => :email_address, :messages => {
:presence => "You have to enter your email address",
:is_unique => "You've already entered",
:format => "That isn't a valid email address" }
property :created_at, DateTime
end
configure :development do
# create, upgrade, or migrate tables automatically
DataMapper.auto_upgrade!
end
enable :sessions
helpers do
include Sinatra::Authorization
end
# Set UTF-8 for outgoing
before do
headers "Content-Type" => "text/html; charset=utf-8"
end
get '/' do
@title = "Enter to win a rad Timbuk2 bag!"
erb :welcome
end
post '/' do
@entry = Entry.new(:first_name => params[:first_name], :last_name => params[:last_name], :email => params[:email])
if @entry.save
redirect("/thanks")
else
session[:errors] = @entry.errors
redirect('/')
end
end
And here is my template:
<h1><%= @title %></h1>
<form action="/" method="post" id="entry">
<p>
<label>First Name: </label><br />
<input type="text" name="first_name" id="first_name" />
</p>
<p>
<label>Last Name: </label><br />
<input type="text" name="last_name" id="last_name" />
</p>
<p>
<label>Apple Email Address: </label><br />
<input type="text" name="email" id="email" />
</p>
<p>
<input type="submit">
</p>
<% if @errors %>
<div id="errors">
<%@errors.each do |e| %>
<p><%= e %></p>
<% end %>
</div>
<% end %>
I'm assuming it has something to do with now I'm using sessions and trying to track the errors, but I'm at a loss.