Checking whether a store is open or not by querying over its business hours
Here's your problem:

&lt;ul&gt;&lt;%= render @stores %&gt;&lt;/ul&gt;

&lt;li&gt;&lt;% if store.open? %&gt;&lt;/li&gt;


You're rendering multiple stores via partials. When each partial is fully rendered out it looks like this:

&lt;ul&gt;
  &lt;li&gt;&lt;% if store.open? %&gt;&lt;/li&gt;
  &lt;li&gt;&lt;% if store.open? %&gt;&lt;/li&gt;
  &lt;li&gt;&lt;% if store.open? %&gt;&lt;/li&gt;
  &lt;li&gt;&lt;% if store.open? %&gt;&lt;/li&gt;
&lt;/ul&gt;


Each call to 

&lt;% if store.open? %&gt;


will result in a db query, which is where your n+1 problem is coming from.

You have 2 options:

1. Eager loading

#pseudocode
#controller
@stores = Store.includes(:business_hours).where(some_condition:...)

#partial
&lt;% if store.is_open?(store.business_hours) %&gt;

#model
def is_open?(business_hours)
   open = business_hours.detect {|h| (h.wday == Time.now.wday) &amp;&amp; ((h.open_time..h.close_time).cover?(Time.now)) }
   open.present? ? true : false
end


May get very memory intensive if you have thousands of stores and many business_hours for each store.

2. Denormalize your database and cache weekdays and business hours in your table

#pseudocode
#migration
table "stores"
   t.integer wday
   t.string open_time
   t.string close_time

#model
def is_open?
  (self.wday == Time.now.wday) &amp;&amp; ((self.open_time.to_time..self.close_time.to_time).cover?(Time.now))
end


The approach you take will depend on how many records you need to deal with at any one time.