I've the next associations:

Outlet => has_many :problems
User => has_many :problems
Checkin => belongs_to :outlet, belongs_to :user

When designing a New Checkin, the consumer_id is placed instantly in the ID from the current user, and also the Outlet is chosen from the drop lower box (which utilizes the openingidentification):

<%= f.collection_select :outlet_id, Outlet.all, :id, :name %>

Every day, each outlet must be checked directly into once.

Im looking to get two pages:

  1. Someone to display all of the Shops that haven't been checked into today.
  2. Someone to display all of the Shops that have been checked into today.

For that second page I believed I possibly could possibly do:

Checkin.where('created_at = Date.today')

But I am not convinced this really is the easiest method to get it done? or even when it might work? I have no idea regarding the way i would display the Shops which haven't been checked into - as I am unsure the way i would obtain the Outlet list, and appearance for every one if your checkin have been made today.

Any help could be greatly appreciated.

UPDATE:

I had been thinking about configuring it to ensure that everyday a checkin is produced for every outlet. But among the fields (i.e.:showed up [which might be a boolean]) might be unchecked. After which whenever a checkin is created, it might just tick the checkbox.

However it has the down-side of making plenty of records unncesccessarily.

I am not really sure there is a great Rails method of carrying this out, but here's my best try:

# All outlet ids into an array
outlets = Outlets.all
outlet_ids = outlets.map(&:id)
# All the outlet ids of the checkins
checked_in = Checkins.where('created_at = Date.today')
checked_in_outlet_ids = checked_in.map(&:outlet_id)
# All outlet ids not in checkins
not_checked_in = outlet_ids - checked_in_outlet_ids

First we grab all of the ids of possible shops. Only then do we query to obtain the shops which were checked in today. We make use of a Proc trick to obtain a range of only the ids on queries. Then we make use of the difference operator on arrays to come back a brand new array known as not_checked_in. This array will contain all of the ids that are not checked in today.