I'm building an events listing site. Currently each event is entered for a specific date and displayed in order......simple! However, I need to consider how to handle events such as festivals and plays that span more than one date. Entering the event over and over again for each date clearly isn't the best option. I've thought I could have a start date and end date, but i'm not sure how I would then make the event show in my index for the dates in between start/end. This is probably really simple, but I just thought i'd seek some guidance for those with more experience before I potentially set off down the wrong path with this.
The event schema at the moment:
create_table "events", :force => true do |t|
t.date "event_date"
t.string "headline"
t.text "info"
t.integer "event_type_id"
t.integer "venue_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "event_image_file_name"
t.string "event_image_content_type"
t.integer "event_image_file_size"
t.datetime "event_image_updated_at"
t.boolean "free"
end
And my Event Controller index does:
@events = Event.paginate(:page => params[:page], :per_page => 12).find(:all, :conditions => ['event_date >= ?', Date.today], :order => "event_date")
EDIT: I should have pointed out that i'm listing the events with a date header generated by the following line in my Event Controllers Index method:
@events_dates = @events.group_by { |e| e.event_date }
The the view is something along the lines of:
<% @events_dates.sort.each do |event_dates, events| %>
<div class="well">
<h3>
<% if event_dates == Date.today %>
Today
<% elsif event_dates == Date.today + 1 %>
Tomorrow
<% else %>
<%= event_dates.to_date.to_formatted_s(:my_format) %>
<% end %>
</h3>
</div>
<%= render events %>
<% end %>
The events partial then has the event headline, info etc.
So, I think what I need to do is alter the way I loop through my date headers. Instead of grouping event dates from the db and then looping those, I almost need to loop through calendar days and see if events occur on those dates based on event_start_date and event_end_date. Any ideas how to approach that?