0

I have this application which general goal is to poll users, aggregate their responses and create pie/bar charts.

My objective is while creating the questions set a time that will define when they are available for the users to see them and therefore answer to them.

What's the best approach to implement something like this? Maybe a background job that will automatically present the questions to the users or, probably when the users refresh the page where the questions should appear verify the elapsed time and present only the questions that are available in that day?

Use case: create a question that will be available tomorrow at 12h and will end at 13h.

Thanks

cbk200
  • 89
  • 1
  • 4

1 Answers1

1

You can just use SQL.

scope :available, -> { where('start_date >= :time AND end_date <= :time', time: Time.current) } 

and then use it in controller or where you want to.

You have good explanation here date scopes

Community
  • 1
  • 1
Argonus
  • 1,005
  • 6
  • 11