Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:19:20+00:00 2026-06-05T15:19:20+00:00

I’m building an events listing site. Currently each event is entered for a specific

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:19:21+00:00Added an answer on June 5, 2026 at 3:19 pm

    If you have a start and end date, using the conditions hash:

    :conditions => ["event_start_date <= ? AND event_end_date >= ?", Date.today, Date.today]
    

    Or arel:

    .where("event_start_date <= ? AND event_end_date >= ?", Date.today, Date.today)
    

    Edit:

    Okay, so you want to iterate over a date range, and then display any events for that day. To iterate over a date range you’d use ruby’s Date.upto() function, and for each date, you could then just iterate over the events, and only display events relevant for the current date.

    The following code is assuming you’ve set up the @start_date and @end_date in the controller.

    <% @start_date.upto(@end_date) do |date| %>
    <div class="well">
    <h3>
    <% if date == Date.today %>
    Today
    <% elsif date == Date.today + 1 %>
    Tomorrow
    <% else %>
    <%= date.to_formatted_s(:my_format) %>
    <% end %>
    </h3>
    </div>
    
    <%= render @events.select{|event| event.start_date < date && event.end_date > date} %>
    <% end %>
    

    There’s a bit too much logic going on in the view here though, and you might have to do a little rejigging to get it to work, but it should get you on the right path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.