Redirect home to conference#show if only one conference live tommorow

This commit is contained in:
divyanshumehta 2017-04-16 10:42:46 +05:30
parent ee7684d845
commit d425349bdd
3 changed files with 4 additions and 7 deletions

View file

@ -13,6 +13,7 @@ class ConferencesController < ApplicationController
def current def current
current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current).first current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current).first
current = Conference.where('start_date = ?', Date.current + 1).first if current.blank?
redirect_to conference_path(current.short_title) redirect_to conference_path(current.short_title)
end end

View file

@ -1,6 +1,7 @@
class RootRouteConstraint class RootRouteConstraint
def initialize def initialize
@current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current).reorder(start_date: :asc) @current = Conference.where('start_date <= ? AND end_date >= ?', Date.current, Date.current)
@current = Conference.where('start_date = ?', Date.current + 1) if @current.blank?
end end
## ##
@ -10,10 +11,6 @@ class RootRouteConstraint
# * +true+ -> only one conferene is live AND the conference has public splashpage # * +true+ -> only one conferene is live AND the conference has public splashpage
# * +false+ -> no or more than one conferences are live or the only live conferece has no public splashpage # * +false+ -> no or more than one conferences are live or the only live conferece has no public splashpage
def matches?(*) def matches?(*)
if @current.present? && @current.first.splashpage.present? @current.present? && @current.first.splashpage.present? && @current.count == 1 && @current.first.splashpage.public?
@current.count == 1 && @current.first.splashpage.public?
else
false
end
end end
end end

View file

@ -34,6 +34,5 @@ describe RootRouteConstraint do
constraint = RootRouteConstraint.new constraint = RootRouteConstraint.new
expect(constraint.matches?).to eq false expect(constraint.matches?).to eq false
end end
end end
end end