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 8066483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:00:43+00:00 2026-06-05T12:00:43+00:00

I have an Event model which contains a start_date field of type datetime .

  • 0

I have an Event model which contains a start_date field of type datetime. I have a simple model method that is supposed to let me know if the start_date is already active, or if it’s yet to happen:

def future_event?
  self.start_date >= DateTime.now
end

Then in my view, I check which view I need to load (based on whether or not the event is happening right now or the event is still in the future). I’ve tried various things like converting both to Time objects, string formatting, etc… Nothing seems to work, the same view is always rendered. Here’s my view code:

<% if @event.future_event? %>
   <%= render "pages/main_container_offline" %>
   <%= render "pages/sidebar_offline" %>
 <% else %>
   <%= render "pages/main_container_online" %>
   <%= render "pages/sidebar_live" %>
<% end %>

Any ideas?

Edit:

Here’s the output of @event.start_date : 2012-06-10 10:20:00 UTC

Here’s the output of DateTime.now : 2012-06-10T10:35:30-05:00

As you can see, the formatting is different. I’m not sure if this is an issue or not.


Here’s my controller method which sets @event:

def index
  @event = Event.active.order("start_date ASC").first
end

## model
scope :active, lambda {
  where("end_date >= ?", DateTime.now)
}
  • 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-05T12:00:45+00:00Added an answer on June 5, 2026 at 12:00 pm

    So, I finally figured this out. Basically the problem was that Rails saves everything in the UTC timezone, which would always be different than my time locally (hence the improper rendering). In order to fix this, I had to tell Rails and ActiveRecord to save everything using my timezone, and display everything in my timezone as well. The following changes fixed my problem:

    application.rb

    config.time_zone = 'Central Time (US & Canada)'
    config.active_record.default_timezone = :local
    

    model.rb

    def future_event?
      self.start_date >= Time.zone.now
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Event model which contains following fields string name date start_at date end_at
Does jquery/javascript have any event model that you can attach to your objects? Basically
I have a model that looks like this: Performance - Location - Event -
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a form that contains a Part Number inputText field and some other
I have a event model that has many invitations. Invitations are setup through checkboxes
I have an HTML link that opens a jQuery modal dialog which contains an
There is model call Event which contains following attributes start_at, end_at, details, trainer This
I have some jQuery that looks like this: $.ajax({ type: POST, url: /Customer/CancelSubscription/<%= Model.Customer.Id
I have a Model than contains a collection of items that can be modified.

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.