Created
June 26, 2013 02:01
-
-
Save chadoh/5864183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
get '/' do | |
haml :index | |
end | |
get '/result' do | |
missed_fields = params.keys.select {|key| params[key].blank? } | |
haml :index and return if missed_fields | |
loan_eligibility = params[:loan_length]/params[:loan_amount] + params[:income] - params[:expenses] | |
haml :result | |
end | |
__END__ | |
@@ layout | |
%html | |
%head | |
%title Terrible Loan Calculator | |
%body | |
= yield | |
@@ index | |
%h1 Enter a potential customer's details and find out if they qualify for a loan! | |
- if missed_fields | |
%h2 Aw, shucks! | |
%p Please fill in #{missed_fields.join(',')}. | |
%form(method='get' action='/result') | |
%input(type='text' name='loan_length' placeholder='loan_length') | |
%input(type='text' name='loan_amount' placeholder='loan_amount') | |
%input(type='text' name='income' placeholder='income') | |
%input(type='text' name='expenses' placeholder='expenses') | |
%input(type='submit' value='Determine loan eligibility') | |
@@ result | |
%h1 Loan Eligibility: #{loan_eligibility} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment