Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a couple of ways you could do this depending on how you app is set up. None of which are unique to the Heroku environment.</p> <p>If your app allows users to sign up then you most probably have a User model, and you may be using the Devise gem for authentication/signup. Add a field to your db (:time_zone) and store the users time zone in this field when they sign up.</p> <pre><code>&gt;&gt; rails generate migration add_time_zone_to_users time_zone:string &gt;&gt; rake db:migrate </code></pre> <p>Rails gives you a handy time_zone_select form helper which gives you a select list with all the Time zones in it which you can display to your user. Add it to the user sign up form and allow the user to set their time zone when signing up. <a href="http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/time_zone_select" rel="nofollow noreferrer">http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/time_zone_select</a></p> <p>In your Application Controller you can then do something like this;</p> <pre><code>before_filter :set_time_zone def set_time_zone #current user is a devise method see https://github.com/plataformatec/devise Time.zone = current_user.time_zone if current_user end </code></pre> <p>Then when you display a date in your app call <code>.in_time_zone</code> on the time instance which will display the time in the users time zone.</p> <pre><code>&lt;%= Time.now.in_time_zone %&gt; or &lt;%= @your_model.created_at.in_time_zone %&gt; </code></pre> <p>If you don't have user authentication then you could fall back to javascript. To do this you could use the native javascript <code>getTimezoneOffset()</code> on the date object, or even better use the following jsTimezoneDetect plugin:</p> <p><a href="http://www.pageloom.com/automatic-timezone-detection-with-javascript" rel="nofollow noreferrer">http://www.pageloom.com/automatic-timezone-detection-with-javascript</a></p> <p>Finally you could use a hybrid of both and firstly detect their time zone offset using javascript and then store this value in a rails session/cookie and then use a before_filter to set the Time.zone as above but based on the session time_zone value previously calculated in javascript.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload