├── Gemfile ├── Gemfile.lock ├── LICENSE ├── Procfile ├── README.md ├── config.ru └── run.sh /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | ruby '2.6.3' 4 | 5 | gem 'rails', '~> 5.2.4' 6 | gem 'puma' 7 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.2.4.4) 5 | actionpack (= 5.2.4.4) 6 | nio4r (~> 2.0) 7 | websocket-driver (>= 0.6.1) 8 | actionmailer (5.2.4.4) 9 | actionpack (= 5.2.4.4) 10 | actionview (= 5.2.4.4) 11 | activejob (= 5.2.4.4) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.2.4.4) 15 | actionview (= 5.2.4.4) 16 | activesupport (= 5.2.4.4) 17 | rack (~> 2.0, >= 2.0.8) 18 | rack-test (>= 0.6.3) 19 | rails-dom-testing (~> 2.0) 20 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 | actionview (5.2.4.4) 22 | activesupport (= 5.2.4.4) 23 | builder (~> 3.1) 24 | erubi (~> 1.4) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 | activejob (5.2.4.4) 28 | activesupport (= 5.2.4.4) 29 | globalid (>= 0.3.6) 30 | activemodel (5.2.4.4) 31 | activesupport (= 5.2.4.4) 32 | activerecord (5.2.4.4) 33 | activemodel (= 5.2.4.4) 34 | activesupport (= 5.2.4.4) 35 | arel (>= 9.0) 36 | activestorage (5.2.4.4) 37 | actionpack (= 5.2.4.4) 38 | activerecord (= 5.2.4.4) 39 | marcel (~> 0.3.1) 40 | activesupport (5.2.4.4) 41 | concurrent-ruby (~> 1.0, >= 1.0.2) 42 | i18n (>= 0.7, < 2) 43 | minitest (~> 5.1) 44 | tzinfo (~> 1.1) 45 | arel (9.0.0) 46 | builder (3.2.4) 47 | concurrent-ruby (1.1.8) 48 | crass (1.0.6) 49 | erubi (1.10.0) 50 | globalid (0.4.2) 51 | activesupport (>= 4.2.0) 52 | i18n (1.8.7) 53 | concurrent-ruby (~> 1.0) 54 | loofah (2.9.0) 55 | crass (~> 1.0.2) 56 | nokogiri (>= 1.5.9) 57 | mail (2.7.1) 58 | mini_mime (>= 0.1.1) 59 | marcel (0.3.3) 60 | mimemagic (~> 0.3.2) 61 | method_source (1.0.0) 62 | mimemagic (0.3.5) 63 | mini_mime (1.0.2) 64 | mini_portile2 (2.5.0) 65 | minitest (5.14.3) 66 | nio4r (2.5.4) 67 | nokogiri (1.11.1) 68 | mini_portile2 (~> 2.5.0) 69 | racc (~> 1.4) 70 | puma (5.1.1) 71 | nio4r (~> 2.0) 72 | racc (1.5.2) 73 | rack (2.2.3) 74 | rack-test (1.1.0) 75 | rack (>= 1.0, < 3) 76 | rails (5.2.4.4) 77 | actioncable (= 5.2.4.4) 78 | actionmailer (= 5.2.4.4) 79 | actionpack (= 5.2.4.4) 80 | actionview (= 5.2.4.4) 81 | activejob (= 5.2.4.4) 82 | activemodel (= 5.2.4.4) 83 | activerecord (= 5.2.4.4) 84 | activestorage (= 5.2.4.4) 85 | activesupport (= 5.2.4.4) 86 | bundler (>= 1.3.0) 87 | railties (= 5.2.4.4) 88 | sprockets-rails (>= 2.0.0) 89 | rails-dom-testing (2.0.3) 90 | activesupport (>= 4.2.0) 91 | nokogiri (>= 1.6) 92 | rails-html-sanitizer (1.3.0) 93 | loofah (~> 2.3) 94 | railties (5.2.4.4) 95 | actionpack (= 5.2.4.4) 96 | activesupport (= 5.2.4.4) 97 | method_source 98 | rake (>= 0.8.7) 99 | thor (>= 0.19.0, < 2.0) 100 | rake (13.0.3) 101 | sprockets (4.0.2) 102 | concurrent-ruby (~> 1.0) 103 | rack (> 1, < 3) 104 | sprockets-rails (3.2.2) 105 | actionpack (>= 4.0) 106 | activesupport (>= 4.0) 107 | sprockets (>= 3.0.0) 108 | thor (1.1.0) 109 | thread_safe (0.3.6) 110 | tzinfo (1.2.9) 111 | thread_safe (~> 0.1) 112 | websocket-driver (0.7.3) 113 | websocket-extensions (>= 0.1.0) 114 | websocket-extensions (0.1.5) 115 | 116 | PLATFORMS 117 | ruby 118 | 119 | DEPENDENCIES 120 | puma 121 | rails (~> 5.2.4) 122 | 123 | RUBY VERSION 124 | ruby 2.6.3p62 125 | 126 | BUNDLED WITH 127 | 2.0.2 128 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Darren Broemmer 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: bundle exec puma -p $PORT -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A mini-Rails application for an instant poll 2 | 3 | The entire application is contained within the config.ru file 4 | 5 | ## Where can I learn more about this? 6 | 7 | Credit to Nate Berkopec for his work on [lightweight Rails stacks](https://github.com/nateberkopec/rails_lightweight_stack) 8 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | require 'action_controller/railtie' 2 | 3 | SURVEY_CHOICES = ["Netflix", "Gaming", "Dining", "NightClub"] 4 | 5 | class SurveyApp < Rails::Application 6 | config.eager_load = true # necessary to silence warning 7 | config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) 8 | config.secret_key_base = SecureRandom.uuid # Rails won't start without this 9 | config.action_dispatch.default_headers = { 'X-Frame-Options' => 'ALLOWALL' } 10 | routes.append { root :to => "survey#index" } 11 | routes.append { post "/survey" => "survey#index" } 12 | end 13 | 14 | class SurveyController < ActionController::Base 15 | @@responses = {} 16 | def index 17 | choice = params["activity_choice"] 18 | if choice 19 | count = @@responses[choice] 20 | count = 0 unless not count.nil? 21 | @@responses[choice] = count + 1 22 | render html: results_html(choice).html_safe 23 | else 24 | render html: form_html.html_safe 25 | end 26 | end 27 | 28 | def form_html 29 | form_start = <<-FORM_START_HTML 30 |

What is your favorite weekend activity?

31 |
32 | FORM_START_HTML 33 | 34 | form_end = <<-FORM_END_HTML 35 |

36 | 37 |
38 |
39 | FORM_END_HTML 40 | 41 | buffer = form_start 42 | SURVEY_CHOICES.each do |choice| 43 | buffer = "#{buffer}#{button_html(choice)}" 44 | end 45 | "#{buffer}#{form_end}" 46 | end 47 | 48 | def button_html(choice) 49 | <<-CHOICE_HTML 50 |
51 | 52 | 53 |
54 | CHOICE_HTML 55 | end 56 | 57 | def results_html(answer) 58 | header = <<-RESULTS_HTML 59 |

What is your favorite weekend activity?

60 | Thanks for participating? You chose #{answer}. Overall results:

61 |
62 | RESULTS_HTML 63 | 64 | buffer = "" 65 | SURVEY_CHOICES.each do |choice| 66 | count = @@responses[choice] 67 | count = 0 unless not count.nil? 68 | buffer = "#{buffer}
#{choice.rjust(10, ' ')}: #{count}
" 69 | end 70 | 71 | "#{header}#{buffer}
" 72 | end 73 | end 74 | 75 | SurveyApp.initialize! 76 | run SurveyApp 77 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | bundle exec puma -p 3000 2 | --------------------------------------------------------------------------------