From 01987cc0b88fdb0748d8d71cca4f5e40ea8a2604 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 5 Oct 2015 20:13:33 +0200 Subject: Redirect back to form and display error if no songs specified. --- registration.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'registration.rb') diff --git a/registration.rb b/registration.rb index e5be8f0..c6598d1 100644 --- a/registration.rb +++ b/registration.rb @@ -1,9 +1,14 @@ require 'sinatra/base' +require 'sinatra/url_for' require_relative 'lib/registration' class RegistrationApp < Sinatra::Base + helpers Sinatra::UrlForHelper + include ERB::Util get '/' do + @errors = request['errors'] + @errors = @errors.split('|') if @errors erb :index end @@ -11,9 +16,13 @@ class RegistrationApp < Sinatra::Base if request.form_data? #p request['band'] @band = Band.new(request['band']) - generate_pdf_for @band - send_registration_emails_for @band - erb :submitted + if @band.valid? + generate_pdf_for @band + send_registration_emails_for @band + erb :submitted + else + redirect to(url_for('/', :errors => @band.errors.join('|'))) + end end end -- cgit v1.2.3