From b89fa43b0e0c2aaefad31633d4215cac5554e2ff Mon Sep 17 00:00:00 2001 From: Godwin Date: Sun, 11 Dec 2016 21:30:08 -0800 Subject: [PATCH] Fixed NPE on schedule --- Gemfile | 80 +++++++++++------------ app/controllers/application_controller.rb | 18 ++--- app/views/application/500.html.haml | 8 +-- app/views/application/_contact.html.haml | 22 +++---- 4 files changed, 65 insertions(+), 63 deletions(-) diff --git a/Gemfile b/Gemfile index cdea679..c3f591d 100644 --- a/Gemfile +++ b/Gemfile @@ -11,9 +11,9 @@ gem 'haml' gem 'nokogiri', '~> 1.6.8.rc2' if Dir.exists?('../lingua_franca') - gem 'lingua_franca', :path => '../lingua_franca' + gem 'lingua_franca', path: '../lingua_franca' else - gem 'lingua_franca', :git => 'git://github.com/lingua-franca/lingua_franca.git' + gem 'lingua_franca', git: 'git://github.com/lingua-franca/lingua_franca.git' end gem 'tzinfo-data' @@ -21,15 +21,15 @@ gem 'sass' gem 'sass-rails' if Dir.exists?('../bumbleberry') - gem 'bumbleberry', :path => "../bumbleberry" + gem 'bumbleberry', path: "../bumbleberry" else - gem 'bumbleberry', :git => 'git://github.com/bumbleberry/bumbleberry.git' + gem 'bumbleberry', git: 'git://github.com/bumbleberry/bumbleberry.git' end if Dir.exists?('../paypal-express') - gem 'paypal-express', :path => "../paypal-express" + gem 'paypal-express', path: "../paypal-express" else - gem 'paypal-express', :git => 'git://github.com/bikebike/paypal-express.git' + gem 'paypal-express', git: 'git://github.com/bikebike/paypal-express.git' end gem 'uglifier', '>= 1.3.0' @@ -48,55 +48,55 @@ gem 'redcarpet' gem 'sidekiq' gem 'letter_opener' gem 'launchy' -gem 'to_spreadsheet', :git => 'git://github.com/glebm/to_spreadsheet.git' +gem 'to_spreadsheet', git: 'git://github.com/glebm/to_spreadsheet.git' group :test do - gem 'rspec' - gem 'rspec-rails' + gem 'rspec' + gem 'rspec-rails' end group :development do - gem 'better_errors' - gem 'binding_of_caller' - gem 'meta_request' - - gem 'capistrano', '~> 3.1' - gem 'capistrano-rails', '~> 1.1' - gem 'capistrano-faster-assets', '~> 1.0' - - gem 'eventmachine', :github => 'krzcho/eventmachine', :branch => 'master' - gem 'thin', :github => 'krzcho/thin', :branch => 'master' + gem 'better_errors' + gem 'binding_of_caller' + gem 'meta_request' + + gem 'capistrano', '~> 3.1' + gem 'capistrano-rails', '~> 1.1' + gem 'capistrano-faster-assets', '~> 1.0' + + gem 'eventmachine'#, :github => 'krzcho/eventmachine', :branch => 'master' + gem 'thin'#, :github => 'krzcho/thin', :branch => 'master' end group :test do - gem 'gherkin3', '>= 3.1.0' - gem 'cucumber' - gem 'cucumber-core' - gem 'cucumber-rails' - - gem 'poltergeist' - gem 'guard-rspec' - gem 'factory_girl_rails' - gem 'coveralls', require: false - gem 'selenium-webdriver' - gem 'simplecov', require: false - gem 'webmock', require: false - gem 'database_cleaner' - gem 'mocha' + gem 'gherkin3', '>= 3.1.0' + gem 'cucumber' + gem 'cucumber-core' + gem 'cucumber-rails' + + gem 'poltergeist' + gem 'guard-rspec' + gem 'factory_girl_rails' + gem 'coveralls', require: false + gem 'selenium-webdriver' + gem 'simplecov', require: false + gem 'webmock', require: false + gem 'database_cleaner' + gem 'mocha' end group :staging, :production, :preview do - gem 'rails_12factor' + gem 'rails_12factor' end group :production, :preview do - gem 'unicorn' - gem 'daemon-spawn' - gem 'daemons' + gem 'unicorn' + gem 'daemon-spawn' + gem 'daemons' end platforms 'mswin', 'mingw' do - group :test do - gem 'wdm', '>= 0.1.0' - end + group :test do + gem 'wdm', '>= 0.1.0' + end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0e358d0..cce8a70 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -586,14 +586,16 @@ class ApplicationController < LinguaFrancaApplicationController end @events.each do | event | - day = event.start_time.midnight.to_date - time = event.start_time.hour.to_f + (event.start_time.min / 60.0) - @schedule[day] ||= {} - @schedule[day][:times] ||= {} - @schedule[day][:times][time] ||= {} - @schedule[day][:times][time][:type] = :event - @schedule[day][:times][time][:length] = (event.end_time - event.start_time) / 3600.0 - @schedule[day][:times][time][:item] = event + if event.present? && event.start_time.present? && event.end_time.present? + day = event.start_time.midnight.to_date + time = event.start_time.hour.to_f + (event.start_time.min / 60.0) + @schedule[day] ||= {} + @schedule[day][:times] ||= {} + @schedule[day][:times][time] ||= {} + @schedule[day][:times][time][:type] = :event + @schedule[day][:times][time][:length] = (event.end_time - event.start_time) / 3600.0 + @schedule[day][:times][time][:item] = event + end end @schedule = @schedule.sort.to_h diff --git a/app/views/application/500.html.haml b/app/views/application/500.html.haml index 32df7fa..30fa659 100644 --- a/app/views/application/500.html.haml +++ b/app/views/application/500.html.haml @@ -1,6 +1,6 @@ = render :partial => 'application/header', :locals => {:image_file => 'parts.jpg'} = row do - = columns(medium: 12) do - %p= _'error.500.description', :p - = render 'contact', cancel_btn: false, contact_reason: :website - \ No newline at end of file + = columns(medium: 12) do + %p= _'error.500.description', :p + = render 'contact', cancel_btn: false, contact_reason: :website + \ No newline at end of file diff --git a/app/views/application/_contact.html.haml b/app/views/application/_contact.html.haml index 1b15399..3475c48 100644 --- a/app/views/application/_contact.html.haml +++ b/app/views/application/_contact.html.haml @@ -1,14 +1,14 @@ - contact_reason ||= nil - locale ||= nil = form_tag (locale.present? ? contact_send_url : url_for_locale(locale, contact_send_path)), class: 'contact-form' do - = emailfield :email, nil, big: true, required: true unless logged_in? - - if contact_reason.present? - = hidden_field_tag :reason, contact_reason - - else - = contact_reason_select - = textfield :subject, nil, required: true, big: true - = textarea :message, nil, required: true, plain: true - .actions - = button_tag :send, value: :send - - if cancel_btn - %button.close.subdued=_'forms.actions.generic.cancel' + = emailfield :email, nil, big: true, required: true unless logged_in? + - if contact_reason.present? + = hidden_field_tag :reason, contact_reason + - else + = contact_reason_select + = textfield :subject, nil, required: true, big: true + = textarea :message, nil, required: true, plain: true + .actions + = button_tag :send, value: :send + - if cancel_btn + %button.close.subdued=_'forms.actions.generic.cancel'