diff --git a/Gemfile b/Gemfile index 21eea5e..d452eac 100644 --- a/Gemfile +++ b/Gemfile @@ -1,61 +1,101 @@ +# frozen_string_literal: true + source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '3.0.4' + +gem 'client_side_validations', github: 'DavyJonesLocker/client_side_validations' # validates forms on the client side + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' +gem 'rails', '~> 7.0.4', '>= 7.0.4.1' + +gem 'rspec-rails' + +# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] +gem 'sprockets-rails' + +# Use sqlite3 as the database for Active Record +gem 'sqlite3', '~> 1.4' + +# Use the Puma web server [https://github.com/puma/puma] +gem 'puma', '~> 5.0' + +# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] +gem 'importmap-rails' + +# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] +gem 'turbo-rails' + +# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] +gem 'stimulus-rails' +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem 'jbuilder' -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.2.1' -# Use postgresql as the database for Active Record +# Use Redis adapter to run Action Cable in production +gem 'redis', '~> 4.0' + +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem 'kredis' + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem 'bcrypt', '~> 3.1.7' gem 'pg' # Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' +gem 'sass-rails' # Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' +gem 'uglifier' # Use CoffeeScript for .coffee assets and views -gem 'coffee-rails', '~> 4.1.0' +gem 'coffee-rails' # See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby +gem 'mini_racer', platforms: :ruby + +gem 'rails_admin', '~> 3.0' + +gem 'survey' # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc +gem 'sdoc', group: :doc -gem 'puma' # app server -gem 'survey' # our gem +gem 'kaminari' gem 'twitter-bootstrap-rails' -gem 'kaminari' # pagination -gem 'client_side_validations', github: 'DavyJonesLocker/client_side_validations' # validates forms on the client side -gem 'newrelic_rpm' # new relic instrumentation (heroku plugin) -# Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', require: false -# Use Unicorn as the app server -# gem 'unicorn' +# Use Sass to process CSS +gem 'sassc-rails' -# Use Capistrano for deployment -# gem 'capistrano-rails', group: :development +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem 'image_processing', '~> 1.2' group :development, :test do - gem 'better_errors' # improves the error page - gem 'binding_of_caller' # used by better_errors - gem 'awesome_print' # awesome variable print - - gem 'pry-rails' - gem 'pry-byebug' #replaces pry-nav in MRI 2.0 - gem 'pry-rescue' # use rescue before a rails command, and if an exception is trigger you will be loaded into a pry session - gem 'pry-stack_explorer' # explore stack calls with up and down - - # Access an IRB console on exception pages or by using <%= console %> in views - gem 'web-console', '~> 2.0' - - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem 'debug', platforms: %i[ mri mingw x64_mingw ] end -gem 'rails_12factor', group: :production +group :development do + # Use console on exceptions pages [https://github.com/rails/web-console] + gem 'web-console' + + # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] + # gem 'rack-mini-profiler' -ruby "2.2.0" \ No newline at end of file + # Speed up commands on slow machines / big apps [https://github.com/rails/spring] + # gem 'spring' +end + +group :test do + # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] + gem 'capybara' + gem 'selenium-webdriver' + gem 'webdrivers' +end diff --git a/Gemfile.lock b/Gemfile.lock index 2e74689..373077c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,222 +1,372 @@ GIT - remote: git://github.com/DavyJonesLocker/client_side_validations.git - revision: 5c1c63e3deb62f1578e1a0b1ad9d4302a4e0fc56 + remote: https://github.com/DavyJonesLocker/client_side_validations.git + revision: 2ac71c5d5162ce948863a5f8b55382fb0ba5bc1e specs: - client_side_validations (4.2.0) - jquery-rails (>= 3.1.2, < 5.0.0) - rails (>= 4.0.0, < 4.3.0) + client_side_validations (21.0.0) + js_regex (~> 3.7) + rails (>= 5.2, < 7.1) + +PATH + remote: ../survey + specs: + survey (0.1) + rails (>= 3.2.6) + railties (>= 3.2.6) GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.1) - actionpack (= 4.2.1) - actionview (= 4.2.1) - activejob (= 4.2.1) + actioncable (7.0.4.2) + actionpack (= 7.0.4.2) + activesupport (= 7.0.4.2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.4.2) + actionpack (= 7.0.4.2) + activejob (= 7.0.4.2) + activerecord (= 7.0.4.2) + activestorage (= 7.0.4.2) + activesupport (= 7.0.4.2) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.4.2) + actionpack (= 7.0.4.2) + actionview (= 7.0.4.2) + activejob (= 7.0.4.2) + activesupport (= 7.0.4.2) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.1) - actionview (= 4.2.1) - activesupport (= 4.2.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - actionview (4.2.1) - activesupport (= 4.2.1) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.4.2) + actionview (= 7.0.4.2) + activesupport (= 7.0.4.2) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.4.2) + actionpack (= 7.0.4.2) + activerecord (= 7.0.4.2) + activestorage (= 7.0.4.2) + activesupport (= 7.0.4.2) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.4.2) + activesupport (= 7.0.4.2) builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - activejob (4.2.1) - activesupport (= 4.2.1) - globalid (>= 0.3.0) - activemodel (4.2.1) - activesupport (= 4.2.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.4.2) + activesupport (= 7.0.4.2) + globalid (>= 0.3.6) + activemodel (7.0.4.2) + activesupport (= 7.0.4.2) + activemodel-serializers-xml (1.0.2) + activemodel (> 5.x) + activesupport (> 5.x) builder (~> 3.1) - activerecord (4.2.1) - activemodel (= 4.2.1) - activesupport (= 4.2.1) - arel (~> 6.0) - activesupport (4.2.1) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - arel (6.0.0) - awesome_print (1.6.1) - better_errors (2.1.1) - coderay (>= 1.0.0) - erubis (>= 2.6.6) - rack (>= 0.9.0) - binding_of_caller (0.7.2) - debug_inspector (>= 0.0.1) - builder (3.2.2) - byebug (3.5.1) - columnize (~> 0.8) - debugger-linecache (~> 1.2) - slop (~> 3.6) - coderay (1.1.0) - coffee-rails (4.1.0) + activerecord (7.0.4.2) + activemodel (= 7.0.4.2) + activesupport (= 7.0.4.2) + activestorage (7.0.4.2) + actionpack (= 7.0.4.2) + activejob (= 7.0.4.2) + activerecord (= 7.0.4.2) + activesupport (= 7.0.4.2) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.4.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) + bindex (0.8.1) + bootsnap (1.16.0) + msgpack (~> 1.2) + builder (3.2.4) + capybara (3.38.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + character_set (1.6.0) + sorted_set (~> 1.0) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.9.1.1) - columnize (0.9.0) - debug_inspector (0.0.2) - debugger-linecache (1.2.0) - erubis (2.7.0) - execjs (2.5.2) - globalid (0.3.5) - activesupport (>= 4.1.0) - i18n (0.7.0) - interception (0.5) - jbuilder (2.2.13) - activesupport (>= 3.0.0, < 5) - multi_json (~> 1.2) - jquery-rails (4.0.3) - rails-dom-testing (~> 1.0) + coffee-script-source (1.12.2) + commonjs (0.2.7) + concurrent-ruby (1.2.0) + crass (1.0.6) + date (3.3.3) + debug (1.7.1) + irb (>= 1.5.0) + reline (>= 0.3.1) + diff-lcs (1.5.0) + erubi (1.12.0) + execjs (2.8.1) + ffi (1.15.5) + globalid (1.1.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + importmap-rails (1.1.5) + actionpack (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.6.0) + irb (1.6.2) + reline (>= 0.3.0) + jbuilder (2.11.5) + actionview (>= 5.0.0) + activesupport (>= 5.0.0) + jquery-rails (4.5.1) + rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.2) - kaminari (0.16.3) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) - loofah (2.0.2) + js_regex (3.10.0) + character_set (~> 1.4) + regexp_parser (>= 2.6.2, < 3.0.0) + regexp_property_values (~> 1.0) + kaminari (1.2.2) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) + actionview + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) + activerecord + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) + less (2.6.0) + commonjs (~> 0.2.7) + less-rails (4.0.0) + actionpack (>= 4) + less (~> 2.6.0) + sprockets (>= 2) + libv8-node (16.10.0.0) + loofah (2.19.1) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.3) - mime-types (>= 1.16, < 3) - method_source (0.8.2) - mime-types (2.5) - mini_portile (0.6.2) - minitest (5.6.1) - multi_json (1.11.0) - newrelic_rpm (3.9.5.251) - nokogiri (1.6.6.2) - mini_portile (~> 0.6.0) - pg (0.18.1) - pry (0.10.1) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - pry-byebug (2.0.0) - byebug (~> 3.4) - pry (~> 0.10) - pry-rails (0.3.2) - pry (>= 0.9.10) - pry-rescue (1.4.1) - interception (>= 0.5) - pry - pry-stack_explorer (0.4.9.1) - binding_of_caller (>= 0.7) - pry (>= 0.9.11) - puma (2.9.1) - rack (>= 1.1, < 2.0) - rack (1.6.1) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.2.1) - actionmailer (= 4.2.1) - actionpack (= 4.2.1) - actionview (= 4.2.1) - activejob (= 4.2.1) - activemodel (= 4.2.1) - activerecord (= 4.2.1) - activesupport (= 4.2.1) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.1) + mail (2.8.0.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + matrix (0.4.2) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.8.1) + mini_racer (0.6.3) + libv8-node (~> 16.10.0.0) + minitest (5.17.0) + msgpack (1.6.0) + nested_form (0.3.2) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.8) + nokogiri (1.14.1) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + pg (1.4.5) + psych (5.0.2) + stringio + public_suffix (5.0.1) + puma (5.6.5) + nio4r (~> 2.0) + racc (1.6.2) + rack (2.2.6.2) + rack-test (2.0.2) + rack (>= 1.3) + rails (7.0.4.2) + actioncable (= 7.0.4.2) + actionmailbox (= 7.0.4.2) + actionmailer (= 7.0.4.2) + actionpack (= 7.0.4.2) + actiontext (= 7.0.4.2) + actionview (= 7.0.4.2) + activejob (= 7.0.4.2) + activemodel (= 7.0.4.2) + activerecord (= 7.0.4.2) + activestorage (= 7.0.4.2) + activesupport (= 7.0.4.2) + bundler (>= 1.15.0) + railties (= 7.0.4.2) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) + rails_admin (3.1.1) + activemodel-serializers-xml (>= 1.0) + kaminari (>= 0.14, < 2.0) + nested_form (~> 0.3) + rails (>= 6.0, < 8) + turbo-rails (~> 1.0) + railties (7.0.4.2) + actionpack (= 7.0.4.2) + activesupport (= 7.0.4.2) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rake (13.0.6) + rbtree (0.4.6) + rdoc (6.5.0) + psych (>= 4.0.0) + redis (4.8.0) + regexp_parser (2.6.2) + regexp_property_values (1.3.0) + reline (0.3.2) + io-console (~> 0.5) + rexml (3.2.5) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (6.0.1) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.11) + rspec-expectations (~> 3.11) + rspec-mocks (~> 3.11) + rspec-support (~> 3.11) + rspec-support (3.12.0) + rubyzip (2.3.2) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.6) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.2) - loofah (~> 2.0) - rails_12factor (0.0.3) - rails_serve_static_assets - rails_stdout_logging - rails_serve_static_assets (0.0.2) - rails_stdout_logging (0.0.3) - railties (4.2.1) - actionpack (= 4.2.1) - activesupport (= 4.2.1) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rdoc (4.2.0) - sass (3.4.13) - sass-rails (5.0.3) - railties (>= 4.0.0, < 5.0) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (~> 1.1) - sdoc (0.4.1) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) - slop (3.6.0) - spring (1.3.5) - sprockets (3.0.3) - rack (~> 1.0) - sprockets-rails (2.2.4) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - survey (0.2) - rails (>= 3.2.6, < 5) - railties (>= 3.2.6, < 5) - thor (0.19.1) - thread_safe (0.3.5) - tilt (1.4.1) - turbolinks (2.5.3) - coffee-rails - twitter-bootstrap-rails (3.2.0) - actionpack (~> 4.1) - execjs (~> 2.2) - rails (~> 4.1) - railties (~> 4.1) - tzinfo (1.2.2) - thread_safe (~> 0.1) - uglifier (2.7.1) - execjs (>= 0.3.0) - json (>= 1.8.0) - web-console (2.1.2) - activemodel (>= 4.0) - binding_of_caller (>= 0.7.2) - railties (>= 4.0) - sprockets-rails (>= 2.0, < 4.0) + tilt + sdoc (2.6.0) + rdoc (>= 5.0) + selenium-webdriver (4.8.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 3.0) + websocket (~> 1.0) + set (1.0.3) + sorted_set (1.0.3) + rbtree + set (~> 1.0) + sprockets (4.2.0) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + sqlite3 (1.6.0) + mini_portile2 (~> 2.8.0) + stimulus-rails (1.2.1) + railties (>= 6.0.0) + stringio (3.0.4) + thor (1.2.1) + tilt (2.0.11) + timeout (0.3.1) + turbo-rails (1.3.3) + actionpack (>= 6.0.0) + activejob (>= 6.0.0) + railties (>= 6.0.0) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + twitter-bootstrap-rails (5.0.0) + actionpack (>= 5.0, < 8.0) + execjs (~> 2.7) + less-rails (>= 3.0, < 5.0) + railties (>= 5.0, < 8.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + web-console (4.2.0) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) + bindex (>= 0.4.0) + railties (>= 6.0.0) + webdrivers (5.2.0) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (~> 4.0) + websocket (1.2.9) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.6.6) PLATFORMS ruby DEPENDENCIES - awesome_print - better_errors - binding_of_caller + bootsnap + capybara client_side_validations! - coffee-rails (~> 4.1.0) - jbuilder (~> 2.0) + coffee-rails + debug + importmap-rails + jbuilder jquery-rails kaminari - newrelic_rpm + mini_racer pg - pry-byebug - pry-rails - pry-rescue - pry-stack_explorer - puma - rails (= 4.2.1) - rails_12factor - sass-rails (~> 5.0) - sdoc (~> 0.4.0) - spring - survey + puma (~> 5.0) + rails (~> 7.0.4, >= 7.0.4.1) + rails_admin (~> 3.0) + redis (~> 4.0) + rspec-rails + sass-rails + sassc-rails + sdoc + selenium-webdriver + sprockets-rails + sqlite3 (~> 1.4) + stimulus-rails + survey! + turbo-rails turbolinks twitter-bootstrap-rails - uglifier (>= 1.3.0) - web-console (~> 2.0) + tzinfo-data + uglifier + web-console + webdrivers + +RUBY VERSION + ruby 3.0.4p208 + +BUNDLED WITH + 2.4.5 diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..5cc2c08 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css \ No newline at end of file diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css b/app/assets/stylesheets/bootstrap_and_overrides.css index e07ccda..80e2f7d 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css +++ b/app/assets/stylesheets/bootstrap_and_overrides.css @@ -1,7 +1,3 @@ /* - =require twitter-bootstrap-static/bootstrap - - Use Font Awesome icons (default) - =require twitter-bootstrap-static/fontawesome - To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites" + *=require twitter-bootstrap-static/bootstrap */ \ No newline at end of file diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less new file mode 100644 index 0000000..97ac67a --- /dev/null +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -0,0 +1,21 @@ +@import "twitter/bootstrap/bootstrap"; + +// Glyphicons are not required by default, uncomment the following lines to enable them. +//@glyphiconsEotPath: font-url("glyphicons-halflings-regular.eot"); +//@glyphiconsEotPath_iefix: font-url("glyphicons-halflings-regular.eot?#iefix"); +//@glyphiconsWoffPath: font-url("glyphicons-halflings-regular.woff"); +//@glyphiconsTtfPath: font-url("glyphicons-halflings-regular.ttf"); +//@glyphiconsSvgPath: font-url("glyphicons-halflings-regular.svg#glyphicons_halflingsregular"); +// +//@import "twitter/bootstrap/glyphicons.less"; + +// Your custom LESS stylesheets goes here +// +// Since bootstrap was imported above you have access to its mixins which +// you may use and inherit here +// +// If you'd like to override bootstrap's own variables, you can do so here as well +// See http://twitter.github.com/bootstrap/customize.html#variables for their names and documentation +// +// Example: +// @link-color: #ff0000; diff --git a/app/controllers/attempts_controller.rb b/app/controllers/attempts_controller.rb index 0c09274..002c4d4 100644 --- a/app/controllers/attempts_controller.rb +++ b/app/controllers/attempts_controller.rb @@ -1,8 +1,10 @@ -class AttemptsController < ApplicationController +# frozen_string_literal: true +# Class AttemptsController +class AttemptsController < ApplicationController helper 'surveys' - before_filter :load_survey, only: [:new, :create] + before_action :load_survey, only: %i[new create] def index @surveys = Survey::Survey.active @@ -13,13 +15,15 @@ def show render :access_error if current_user.id != @attempt.participant_id end + def destroy; end + def new @participant = current_user - unless @survey.nil? - @attempt = @survey.attempts.new - @attempt.answers.build - end + return if @survey.nil? + + @attempt = @survey.attempts.new + @attempt.answers.build end def create @@ -29,7 +33,7 @@ def create correct_options_text = @survey.correct_options.present? ? 'Bellow are the correct answers marked in green' : '' redirect_to attempt_path(@attempt.id), notice: "Thank you for answering #{@survey.name}! #{correct_options_text}" else - build_flash(@attempt) + build_flash(@attempt) @participant = current_user render :new end @@ -47,10 +51,12 @@ def load_survey end def params_whitelist - if params[:survey_attempt] - params[:survey_attempt][:answers_attributes] = params[:survey_attempt][:answers_attributes].map { |attrs| { question_id: attrs.first, option_id: attrs.last } } - params.require(:survey_attempt).permit(Survey::Attempt::AccessibleAttributes) + return unless params[:survey_attempt] + + params[:survey_attempt][:answers_attributes] = params[:survey_attempt][:answers_attributes].as_json.map do |attrs| + { question_id: attrs.first, option_id: attrs.last } end + params.require(:survey_attempt).permit(Survey::Attempt::AccessibleAttributes) end def current_user diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index c670ef2..3a1a96c 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -1,10 +1,12 @@ -class SurveysController < ApplicationController +# frozen_string_literal: true - before_filter :load_survey, only: [:show, :edit, :update, :destroy] +# Class SurveysController +class SurveysController < ApplicationController + before_action :load_survey, only: %i[show edit update destroy] def index type = view_context.get_survey_type(params[:type]) - query = if type then Survey::Survey.where(survey_type: type) else Survey::Survey end + query = type ? Survey::Survey.where(survey_type: type) : Survey::Survey @surveys = query.order(created_at: :desc).page(params[:page]).per(15) end @@ -22,14 +24,12 @@ def create end end - def edit - end + def edit; end - def show - end + def show; end def update - if @survey.update_attributes(params_whitelist) + if @survey.update(params_whitelist) default_redirect else build_flash(@survey) @@ -38,6 +38,8 @@ def update end def destroy + return unless current_user + @survey.destroy default_redirect end @@ -55,5 +57,4 @@ def load_survey def params_whitelist params.require(:survey_survey).permit(Survey::Survey::AccessibleAttributes << :survey_type) end - end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 88e4676..01070c9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,13 +1,13 @@ class UsersController < ApplicationController def create session[:user_id] = User.create(user_params).id - redirect_to :back + redirect_to root_path end def change_name @user = User.find(params[:id]) @user.update(user_params) - redirect_to :back + redirect_to root_path end def user_params diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4ec01a1..9a754ab 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,11 +1,14 @@ +# frozen_string_literal: true + +# Module ApplicationHelper module ApplicationHelper - def build_flash model - if model.errors.count > 0 - flash.now[:alert] = model.errors.full_messages.join('
').html_safe - end + def build_flash(model) + return if model.errors.full_messages.length.positive? + + flash.now[:alert] = model.errors.full_messages.join('
').html_safe end - def correct_flash_name name + def correct_flash_name(name) case name when 'alert' 'danger' @@ -16,25 +19,29 @@ def correct_flash_name name end end - def is_active?(link_path) + def is_active?(link_path) # rubocop:disable Naming/PredicateName current_page?(link_path) ? 'active' : nil end def current_user @user ||= User.find_by(id: session[:user_id]) + @user end - def user_form + def user_form(&block) common_options = { validate: true, html: { class: 'user-form' } } - form_options = current_user ? [ current_user, { url: change_user_name_path(current_user.id), method: :post, validate: true }.merge(common_options) ] : [ User.new, { validate: true }.merge(common_options) ] - form_for *form_options do |f| - yield f - end + form_options = if current_user + [current_user, { url: change_user_name_path(current_user.id), + method: :post, validate: true }.merge(common_options)] + else + [User.new, { validate: true }.merge(common_options)] + end + form_for(*form_options, &block) end private - - def number_of_people_who_also_answered_count option_id + + def number_of_people_who_also_answered_count(option_id) Survey::Answer.where(option_id: option_id).count end end diff --git a/app/helpers/surveys_helper.rb b/app/helpers/surveys_helper.rb index a710ee4..c390ec0 100644 --- a/app/helpers/surveys_helper.rb +++ b/app/helpers/surveys_helper.rb @@ -1,7 +1,14 @@ +# frozen_string_literal: true + +# Module SurveysHelper module SurveysHelper - def link_to_remove_field(name, f) - f.hidden_field(:_destroy) + - __link_to_function(raw(name), "removeField(this)", :id =>"remove-attach", class: 'btn btn-default') + SURVEY_TYPES = { 0 => 'quiz', + 1 => 'score', + 2 => 'poll' }.freeze + + def link_to_remove_field(name, field) + field.hidden_field(:_destroy) + + __link_to_function(raw(name), 'removeField(this)', id: 'remove-attach') end def new_survey @@ -13,45 +20,51 @@ def edit_survey(resource) end def survey_scope(resource) - if action_name =~ /new|create/ + case action_name + when /new|create/ surveys_path(resource) - elsif action_name =~ /edit|update/ + when /edit|update/ survey_path(resource) end end + def new_attempt + new_attempt_path + end + def attempt_scope(resource) - if action_name =~ /new|create/ - attempts_path(resource) - elsif action_name =~ /edit|update/ + case action_name + when /new|create/ + attempts_path(resource) + when /edit|update/ attempt_path(resource) end end - def link_to_add_field(name, f, association) - new_object = f.object.class.reflect_on_association(association).klass.new - fields = f.fields_for(association, new_object,:child_index => "new_#{association}") do |builder| - render(association.to_s.singularize + "_fields", :f => builder) + def link_to_add_field(name, fld, association) + new_object = fld.object.class.reflect_on_association(association).klass.new + fields = fld.fields_for(association, new_object, child_index: "new_#{association}") do |builder| + render("#{association.to_s.singularize}_fields", f: builder) end __link_to_function(name, "addField(this, \"#{association}\", \"#{escape_javascript(fields)}\")", - :id=>"add-attach", - :class=>"btn btn-default") + id: 'add-attach', + class: 'btn btn-small btn-info') end - def get_answer_fields attempt + def get_answer_fields(attempt) attempt.survey.questions.map { |q| Survey::Answer.new(question_id: q.id) } end - def the_chosen_one? answer, option - if answer.option_id == option.id then 'chosen' else nil end + def the_chosen_one?(answer, option) + answer.option_id == option.id ? 'chosen' : nil end - def number_of_people_who_also_answered option_id + def number_of_people_who_also_answered(option_id) count = number_of_people_who_also_answered_count(option_id) " #{count} #{'answer'.pluralize}".html_safe end - def get_color_of_option answer, option + def get_color_of_option(answer, option) if is_quiz?(answer.question.survey.survey_type) if option.correct 'bg-success' @@ -63,57 +76,54 @@ def get_color_of_option answer, option end end - def get_survey_type survey_type - get_survey_types[survey_type] || get_survey_types.invert[survey_type] + def get_survey_type(survey_type) + key, _value = survey_type + SURVEY_TYPES[key] || SURVEY_TYPES.invert[key] end - def get_survey_types - { 0 => 'quiz', - 1 => 'score', - 2 => 'poll' } + def is_quiz?(something) # rubocop:disable Naming/PredicateName + [0, 'quiz'].include?(something) end - def is_quiz? something - something == 0 || something == 'quiz' + def is_score?(something) # rubocop:disable Naming/PredicateName + [1, 'score'].include?(something) end - def is_score? something - something == 1 || something == 'score' + def is_poll?(something) # rubocop:disable Naming/PredicateName + [2, 'poll'].include?(something) end - def is_poll? something - something == 2 || something == 'poll' - end - - def get_weight option + def get_weight(option) return unless is_score?(option.question.survey.survey_type) - option.weight > 0 ? "(+#{option.weight})" : "(#{option.weight})" + + option.weight.positive? ? "(+#{option.weight})" : "(#{option.weight})" end - def get_weight_html_class option - return 'bg-warning' if option.weight == 0 - option.weight > 0 ? 'bg-success' : 'bg-danger' + def get_weight_html_class(option) + return 'bg-warning' if option.weight.zero? + + option.weight.positive? ? 'bg-success' : 'bg-danger' end - def surveys_count type = get_survey_types.keys - Survey::Survey.where(survey_type: type).count + def surveys_count(type = SURVEY_TYPES.keys) + ::Survey::Survey.where(survey_type: type).count end - def number_of_questions survey + def number_of_questions(survey) survey.questions.count end - def number_of_attempts survey + def number_of_attempts(survey) survey.attempts.count end private - def __link_to_function(name, on_click_event, opts={}) + def __link_to_function(name, on_click_event, opts = {}) link_to(name, 'javascript:;', opts.merge(onclick: on_click_event)) end - def has_weights? survey + def has_weights?(survey) # rubocop:disable Naming/PredicateName survey.questions.map(&:options).flatten.any? { |o| o.weight != 0 } end end diff --git a/app/views/surveys/_form.html.erb b/app/views/surveys/_form.html.erb index 5315e19..f123cdd 100644 --- a/app/views/surveys/_form.html.erb +++ b/app/views/surveys/_form.html.erb @@ -35,7 +35,7 @@ <%= link_to_add_field 'Add a new Question', f, :questions %> <%= f.submit 'Submit', class: 'pull-right btn btn-primary' %> - <% end -%> + <% end %>