Mike Wiesenhart Mike Wiesenhart - 1 year ago 68
SQL Question

Rails 4 hiding span in view

I have a span that will display when an open house is detected in the db using

<% if listing.open_houses.exists? %>
. I need it to not be displayed when the date/time has passed. I have a controller method that does that for the open house itself, but not sure how to do it for the span in the view. I included the controller code below as a reference. Thanks for any help!

Controller Method:

@open_houses = OpenHouse.upcoming.where(listing_id: @listing.id).where('open_houses.start_date >= ?', Date.current).order(start_date: :asc)

Answer Source

I was able to use<% if @open_houses.count >= 1 %>! Something small and silly that took me way too much time to figure out.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download