86cb627120
Since we're rendering according to the local timezone, we'll need to include events that fall before or after the specific date on the server, as they might get be inside the current day in the client's timezone. So let's just grab a window of events either side of today, and then hide anything that falls outside the client's day.
27 lines
669 B
Ruby
27 lines
669 B
Ruby
class EventsController < ApplicationController
|
|
before_action :set_activity_day
|
|
|
|
def index
|
|
@events = Event.
|
|
where(bubble: user_bubbles).
|
|
where(created_at: @activity_day.yesterday.beginning_of_day..@activity_day.tomorrow.end_of_day)
|
|
|
|
@next_day = @activity_day.yesterday.strftime("%Y-%m-%d")
|
|
end
|
|
|
|
private
|
|
def user_bubbles
|
|
Current.user.accessible_bubbles.published_or_drafted_by(Current.user)
|
|
end
|
|
|
|
def set_activity_day
|
|
@activity_day = if params[:day].present?
|
|
Time.zone.parse(params[:day])
|
|
else
|
|
Time.zone.now
|
|
end
|
|
rescue ArgumentError
|
|
raise ActionController::RoutingError
|
|
end
|
|
end
|