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

  • Home
  • SEARCH
  • 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 829457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:53:10+00:00 2026-05-15T03:53:10+00:00

Steps to produce this: prompt>rails test_app prompt>cd test_app prompt>script/generate scaffold date_test my_date:datetime prompt>rake db:migrate

  • 0

Steps to produce this:

prompt>rails test_app
prompt>cd test_app
prompt>script/generate scaffold date_test my_date:datetime
prompt>rake db:migrate

now edit your app/views/date_tests/edit.html.erb:

<h1>Editing date_test</h1>

<% form_for(@date_test) do |f| %>
  <%= f.error_messages %>
  <p>
    RIGHT!<br/>
    <%= text_field_tag @date_test, f.object.my_date %>
  </p>
  <p>
    WRONG!<br />
    <%= f.text_field :my_date %>
  </p>
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>

<%= link_to 'Show', @date_test %> |
<%= link_to 'Back', date_tests_path %>

now edit your config/environment.rb:

#add this
config.time_zone = 'Central Time (US & Canada)'

This recreates the problem I am having in my actual app. The problem with my app is that I’m storing a date in a hidden field and rendering a “user friendly” version. Creating a resource works fine but as soon as I try to edit it the time changes (it adds the difference between my current time zone configuration and UTC). go to http://localhost:3000/date_tests/new and save the time then go to reedit it and you will have two different representations of the date/time one which will save incorrectly and the other that will.

EDIT: One might ask why not just use the one that works. The problem with this is that I am using a nested attribute so i can’t exactly do this. I tried doing this:

# from my real app:
<% appt.fields_for :time_slot do |ts| %>
  <%=h ts.object.start_at.strftime('%T') %>
  <%= hidden_field ts.object.start_at, :start_at %>
  <%= hidden_field ts.object.end_at, :end_at %>
<% end %>

but the html results as:

<div>

      10:00:00
      <input id="2010-05-30_10:00:00_-0500_start_at" name="2010-05-30 10:00:00 -0500[start_at]" type="hidden">
      <input id="2010-05-30_10:10:00_-0500_end_at" name="2010-05-30 10:10:00 -0500[end_at]" type="hidden">
      <input id="appointment_block_appointments_attributes_0_time_slot_attributes_id" name="appointment_block[appointments_attributes][0][time_slot_attributes][id]" type="hidden" value="95">
</div>
  • 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-05-15T03:53:10+00:00Added an answer on May 15, 2026 at 3:53 am

    ok it turns out that i need to override the “convention” and have something like:

    <%= ts.hidden_field :start_at, :value => ts.object.start_at %>
    

    using :value will give me the timezone difference as well which fixed my problem!

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

Sidebar

Related Questions

First steps in FreeBSD: trying to run my installation script. Fast help needed: #
I am trying to do rather complex SQL query to produce a report. This
The steps I go through... Add new ADO.NET Entity Data Model > Generate from
Out of interest, why on windows does this produce a warning (and returns false):
Can someone please explain the steps this program takes and the order in which
Steps: Run the build including unit tests. Expected result: the unit tests are executed
What steps I need to perform in order to convert asp.net 2 application from
Rep steps: create example .NET form application put a TextBox on the form wire
What steps do I take? Any gotchas to be aware of or tips to
What steps do I have to take to configure my sendmail server to implement

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.