ruby on rails 4 - Sorting events to show this week, month etc -


i have list of events i'm struggling work out how show specific date ranges in index view.

i list events showing events today, week, month etc.

i'm new rails i've tried use site , i've come following works today's events.

@events_today = event.find(:all, :conditions => ["date between ? , ?", date.today, date.tomorrow]) 

but i'm not sure how set page automatically update , show weeks events , month.

your basic query should this:

event.where(date: date_range) 

now before calling query can set date range variable. if want week:

date_range  = date.today.beginning_of_week..date.today event.where(date: date_range) 

now there sorts of things can do. can select start , end date or custom period using either form or dropdown select. in case date_range set based on params. use 1 predefined period.

if want work several date range periods nice have last_week, last_month, etc. scope in model (or concern). or define date_range constants in initializers.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -