Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (35 sloc) 1.28 KB
require 'pp'
class FormValidator
def initialize(app)
@app = app
def call(env)
request =
items = [age,name,title,content]
for items.each do |thing|
# how to abstract this?
field_name = "age"
formbox_value = request.env.fetch("rack.request.form_hash", {}).fetch("post", {})[field_name]
# How am I calling the YML file?
pp "LOOK AT ME !!!!!!!!!!!!!!!!!"
pp formbox_value
# TODO abstract these things out so that you can create a hash and then serializ the Hash.
# You want to eventually pull all this out and offer it as middleware anyone can use.
# part 1 - kill duplication
# part 2 - pull things out into yml file
# if the form is not empty
if request.env["rack.request.form_hash"] != nil
# if name is empty send error
if formbox_value == ""
raise'Forgot to enter your #{field_name}....hit the browser back button')
elsif formbox_value= /\d+/.match(age_value) == nil
raise'Forgot to enter your age....hit the browser back button')
p "nil indicator here !!!!!!!"
Something went wrong with that request. Please try again.