Rails app config.time_zone not applying when populating form fields for '/edit' view

前端 未结 3 695
后悔当初
后悔当初 2021-01-03 02:17

I specified config.time_zone in my Rails app, but the retrieved times in form fields still render as the UTC (which creates problems on updates). Shouldn\'t this be convert

相关标签:
3条回答
  • 2021-01-03 02:27

    It turns out the real problem was in the text_fields themselves.

    My 'config.time_zone' setting was working just fine (without any extra methods or hacks) in my 'index' and 'show' views, and it worked in the 'edit' view, too, as long as I used a datetime_select instead of a text_field.

    As this wasn't an option for me (I was using jQuery UI's DatePicker, which needs a text_field), I investigated the text_field specific problem and answered another StackOverflow question of my own on the subject.

    If you're having the text_field problem, check out that question/answer.

    0 讨论(0)
  • 2021-01-03 02:41

    Just use this:

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

    I create a little app for this and it's works.

    0 讨论(0)
  • 2021-01-03 02:42

    You can do something like this:

    heroku config:add TZ=America/Chicago
    

    That should fix your issue on Heroku.

    0 讨论(0)
提交回复
热议问题