top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to use datetime_select to edit an existing model record, that takes in account for time zones in Rails?

+2 votes

I am trying to write a simple calendar app and having troubles with time zones. For as many nice Date and Time helpers, action view and active record sure dont play nice with time zones.

I have an appointment model with the appointment_time attribute which is a datetime. My current issue is editing appointment_time with datetime_select within a form tag.

def appt_time
appointment_time.in_time_zone(time_zone) #this is the appointment owners time zone 

This gives a select with the current date and time in UTC, not the appointment date and time. appt_time does get called and returns the correct date and time adjusted for the time zone.

The docs mention nothing about time zones, what is the best way to accomplish this?

posted Dec 4, 2015 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
0 votes

I am using Eclipse for my Ruby project. Is there a setting I can set to stop eclipse from building all the time? A typical build for my small project takes like 4 hours. so I cant even work when it kicks off a build.

+2 votes

I'd like to remove all existing constraints from an ActiveRecord::Relation and leave the rest in-tact.
I am NOT looking for #unscoped since I would like to keep any joins/order clauses around.

Additionally, I would like to re-use the constraints that were removed in another query, so the ability to call #to_sql on them would be a very nice bonus.

This is the best I've been able to hack together:

Order.where(id: 1).where(id: 2).arel.constraints[0].to_sql
 => "`orders`.`id` = 1 AND `orders`.`id` = 2"

...but that just seems wrong. As far as I can tell #constraints always has one item in it, but I don't know that will always be true.

+1 vote

how to use single login page for users in four models when using Ruby on Rails