Skip to content

Commit

Permalink
Set event default start date to a week from now
Browse files Browse the repository at this point in the history
Also round time to the nearest hour using the Rounding gem.
  • Loading branch information
lujanfernaud committed May 12, 2018
1 parent 6cbf042 commit f70c113
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ gem 'gravatar_image_tag', '~> 1.2'
gem 'inline_svg', '~> 1.3', '>= 1.3.1'
gem 'faker', '~> 1.8', '>= 1.8.7'

# Used to round time to the nearest hour.
gem 'rounding', '~> 1.0', '>= 1.0.1'

# Add type-casting and other features on top of ActiveRecord::Store.store_accessor
gem 'storext', '~> 2.2', '>= 2.2.2'

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rolify (5.2.0)
rounding (1.0.1)
rubocop (0.55.0)
parallel (~> 1.10)
parser (>= 2.5)
Expand Down Expand Up @@ -409,6 +410,7 @@ DEPENDENCIES
rails-controller-testing (~> 1.0, >= 1.0.2)
rails-erd (~> 1.5, >= 1.5.2)
rolify (~> 5.2)
rounding (~> 1.0, >= 1.0.1)
rubocop-rails (~> 1.3)
sass-rails (~> 5.0)
simplecov
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ def see_all_attendees_link(event, quantity:)
link_to "See all attendees", event_attendances_path(event)
end
end

def default_start_date
1.week.from_now.round_to(1.hour)
end

def default_end_date
(1.week.from_now + 1.hour).round_to(1.hour)
end
end
10 changes: 6 additions & 4 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@
<small class="text-muted">Required *</small>
</div>
<div class="col-md-auto">
<%= f.datetime_select :start_date, start_year: Time.now.year,
end_year: Time.now.year + 1, class: "form-control custom-select",
<%= f.datetime_select :start_date, default: default_start_date,
start_year: Time.now.year, end_year: Time.now.year + 1,
class: "form-control custom-select",
required: true %>
</div>
</div>
Expand All @@ -99,8 +100,9 @@
<small class="text-muted">Required *</small>
</div>
<div class="col-md-auto">
<%= f.datetime_select :end_date, start_year: Time.now.year,
end_year: Time.now.year + 1, class: "form-control custom-select" %>
<%= f.datetime_select :end_date, default: default_end_date,
start_year: Time.now.year, end_year: Time.now.year + 1,
class: "form-control custom-select" %>
</div>
</div>
</div>
Expand Down

0 comments on commit f70c113

Please sign in to comment.