Rails 'config.time_zone' doesn't apply to datetime data loaded into a text_field. Fix? -


when use datetime_select in form, rails correctly adjust timezone of datetime data (as per config.time_zone setting), , render properly-zoned time in edit view of same form.

but when try retrieve same data text_field (for same edit view of same form), rails doesn't seem adjust time zone.

/events/edit.html.erb (full file):

<h1>edit event</h1> <%= form_for(@event) |f| %>     <%= render 'fields', :f => f %>     <div class="actions">         <%= f.submit "update event" %>     </div> <% end %> 

/events/_fields.html.erb (relevant lines only:)

<div class="field">     <%= f.label      :time_start, "start time" %><br />     <%= f.text_field  :time_start, :class => "datetimefield" %> </div> 

example: zone's offset -500. enter 8:00 start_time in form, 13:00 utc written database, 8:00 rendered on show page (thanks config.time_zone accounting offset), when try edit object, form's text_field start_time loaded 13:00 (which, if submitted unaltered, becomes 18:00 when it's stored in database).

this problematic, because i'm trying use jquery ui's datepicker (with timepicker add-on), relies on text_field (won't work datetime_select).

is there way make rails apply config.time_zone offset text fields?

running rails 3.0.5, deploying heroku.

apologies in advance having asked similar question few weeks ago. information there still applies, have better understanding of problem now, re-asked.

as said in question, main problem had getting activerecord apply existing 'config.time_zone' setting text_fields.

it turns out there's simple , future-proof way make happen: explicitly add :value , pull exact same data--no extra/new methods call! in case, meant:

<%= f.text_field  :time_start, :value => f.object.time_start, :class => "datetimefield" %> 

this intermediary step potential solution going try, , surprised find worked on own (again, working 'config.time_zone' i'd set in 'config/application.rb').

i've tested it, , applies proper dst offset when applicable (just 1 expect, since 'config.time_zone' set).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -