summaryrefslogblamecommitdiffstats
path: root/registration.rb
blob: ac1a362d1cb56e3bb4f736352f597b67c2215e46 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                      
                         
                             
                  
                                   

                                     
                              

                               
 
                                                    
 
            
                    
                                       


              

                         
                                       
                     
                                                                                                          


                                          
                  
         


       

                        
require 'sinatra/base'
require 'sinatra/url_for'
require 'sinatra/config_file'
require 'tilt/erb'
require_relative 'lib/registration'

class RegistrationApp < Sinatra::Base
  register Sinatra::ConfigFile
  helpers Sinatra::UrlForHelper
  include ERB::Util

  config_file File.join(settings.root, 'config.yml')

  get '/' do
    @band = Band.new
    3.times { @band.songs << Song.new }
    erb :index
  end

  post '/submit' do
    if request.form_data?
      @band = Band.new(request['band'])
      if @band.valid?
        generate_pdf_for(@band, File.join(settings.public_folder, "uploads", create_pdf_file_name(@band)))
        send_registration_emails_for @band
        erb :submitted
      else
        erb :index
      end
    end
  end

  run! if app_file == $0
end