Commit 08581a0c4af9055a406ea11c401584ece08d3c2d
1 parent
c09e6cd1
Exists in
master
and in
22 other branches
SearchController: avoid invalid dates
You cannot use Date.today.day together with arbitrary year/month combinations, because will crash on 2014-10-31 and you are viewing the page for 2014-11 (2014-11-31 is not a valid date).
Showing
1 changed file
with
8 additions
and
4 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -90,10 +90,14 @@ class SearchController < PublicController | @@ -90,10 +90,14 @@ class SearchController < PublicController | ||
90 | end | 90 | end |
91 | 91 | ||
92 | def events | 92 | def events |
93 | - year = (params[:year] ? params[:year].to_i : Date.today.year) | ||
94 | - month = (params[:month] ? params[:month].to_i : Date.today.month) | ||
95 | - day = (params[:day] ? params[:day].to_i : Date.today.day) | ||
96 | - @date = build_date(year, month, day) | 93 | + if params[:year].blank? && params[:year].blank? && params[:day].blank? |
94 | + @date = Date.today | ||
95 | + else | ||
96 | + year = (params[:year] ? params[:year].to_i : Date.today.year) | ||
97 | + month = (params[:month] ? params[:month].to_i : Date.today.month) | ||
98 | + day = (params[:day] ? params[:day].to_i : 1) | ||
99 | + @date = build_date(year, month, day) | ||
100 | + end | ||
97 | date_range = (@date - 1.month).at_beginning_of_month..(@date + 1.month).at_end_of_month | 101 | date_range = (@date - 1.month).at_beginning_of_month..(@date + 1.month).at_end_of_month |
98 | 102 | ||
99 | @events = [] | 103 | @events = [] |