So I have a weekly calendar view and I have a route set up to accept /:year/:month/:day for the start date.
match "events/(:year/:month/:day)" => "events#index",
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ },
:as => "events_date"
I have two questions regarding the use of this route. First, when parsing the params, this is what I'm doing:
unless params[:year].nil? || params[:month].nil? || params[:day].nil?
start_date = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i)
end
start_date = start_date.nil? ? Date.today : start_date
This strikes me as pretty verbose and kind of ugly. Is there a better way?
And when making a link to another week in the calendar (for paging week to week), do I have to do something like
#assume an date object with the desired start date
link_to events_date_path(date.strftime('%Y'), date.strftime('%m'), date.strftime('%d'))
Which also seems kind of verbose and ugly. What's the best way to work with dates in routes?