Rails 4.2 doesn't update datetime fields

I think I found a bug but I am not 100% sure if it is one or I am doing something wrong. I am setting up the timezone like this:

inside application.rb

... config.i18n.default_locale = :en config.time_zone = 'Melbourne' config.active_record.default_timezone = 'Melbourne' ...

When I am updating a model with timestamp columns (created_at, updated_at) it doesn't update them. The problem is caused by this line config.active_record.default_timezone = 'Melbourne' (when I remove it, it works fine). The query seems to be fine but when you reload the model the timestamps are nil. I think the problem appears in all the datetime columns and it doesn't matter which database you are using (I managed to reproduce it in postgres and in sqlite).

Is this something that I would expect because I forgot to configure something or is it a bug?

-------------Problems Reply------------

config.active_record.default_timezone accepts only two values:

  • :local
  • :utc

What you can do is set:

config.time_zone = 'Melbourne'

and then

config.active_record.default_timezone = :local

will do the trick.

Category:ruby on rails Views:1 Time:2018-03-26

Related post

  • How to update DATETIME field with existing data from same table 2010-08-15

    I have an sqlite database which currently holds an integer field called Year which currently only stores the year. In future versions I want to store a full date and time. I updated my table to include a FullDate field using alter table. > ALTER T

  • How to update datetime field 2009-12-22

    What is the best way to update a datetime field in a form. I have a form and need to update both the date and the time. I need to update the date with a date_select and then update the time using a time_select I only have 1 field in my database. Even

  • Update datetime field 1.5 hours from another field 2011-04-19

    I have 2 datetime fields in a single table. dt1 and dt2. dt1 has time data in it. I need to run a query that updates dt2 to 1.5 hours ahead of dt1. How can I update dt2 with a relative time to dt1? --------------Solutions------------- Here is your qu

  • Ruby on Rails HABTM association doesn't update join table 2012-02-25

    I've a many-to-many association of Tags and Users. when I create a tag my join-table doesn't update, I think there's something with the controller.. tag model class Tag < ActiveRecord::Base validates :tag, :presence => true has_and_belongs_to_m

  • update DateTime field with webservice UpdateListItems 2009-10-09

    is it possible to set a DateTime filed to be null/empty when calling UpdateListItems? I can set the field to a date value, but not set it to be empty. --------------Solutions------------- Yes, it's possible. I have tested with both a required and non

  • SQL Server 2005 Express cannot update datetime field when windows is set to Italian 2009-07-13

    I am struggling with an MS SQL 2005 Express issue. A query like the one below works perfect when Windows Regional Options (control panel) is set to English (United States), but it fails when set to Italian (and maybe other languages). UPDATE MyTable

  • Rails, date search query from a datetime field. Why this one does not work? 2012-04-17

    I am new in this world of Rails, so sorry if the mistake is too obvious. I am building a search form. I managed to compare strings. However I am struggling with dates. This is in the form: = select_datetime Date.today, :prefix => :search_start_dat

  • Event Macro That Doesn't Update One Field 2014-10-16

    Is there any way for me to modify this code so that it only puts an "X" in column J and the current date in column k the first time someone enters info in columns B through I? In other words, those two columns should never change once the info is sta

  • Rails 3 not saving time part in datetimes fields 2011-06-10

    I notice that my rails 3 app is saving the datetime field without the time part only the date. I working with mysql. My migration is like this: class CreateCampaigns < ActiveRecord::Migration def self.up create_table :campaigns do |t| t.string :na

  • How do you update a DateTime field in T-SQL? 2010-06-29

    The following query does not update the datetime field: update table SET EndDate = '2009-05-25' WHERE Id = 1 I also tried it with no dashes, but that does not work either. --------------Solutions------------- When in doubt, be explicit about the data

  • How to update a datetime field with PHP MySQL? 2010-11-17

    How doesn't this work? Please help!!! $query = "UPDATE User SET updated_date = NOW() WHERE pk_item = '$id'"; mysqli_query($this->link,$query); if(mysqli_errno($this->link)) return -1; return 1; Thanks --------------Solutions------------- check

  • Updating last_viewed field rails 2011-03-09

    I have a field that stores the last_viewed time. Is the best way to update this field by doing: @course_enrollment.last_viewed = Time.now @course_enrollment.save() This field is a datetime as the database type and a timestamp as the rails migration t

  • Trouble Handling DateTime fields in Rails 3.1 2012-02-17

    When a record is updated or created in MYSQL, the timestamp property stores the time and subtracts 0530hrs from the current system time. I want it to store the system time as is. Below is one of such tables: class CreateUsers < ActiveRecord::Migra

  • Update only Time in a mysql DateTime field 2009-08-25

    How can I update only the time in an already existing DateTime field in MySQL? I want the date to stay the same. --------------Solutions------------- Try this: UPDATE yourtable SET yourcolumn=concat(date(yourcolumn), ' 21:00:00') WHERE Id=yourid; Try

  • T-SQL: How to update just date part of datetime field? 2009-08-26

    In SQL Server 2008 I need to update just the date part of a datetime field. In my stored procedure I receive the new date in datetime format. From this parameter I have to extract the date (not interested in time) and update the existing values date

  • How to alter a DateTime field when it is updated? 2009-12-10

    Is there a database level function (trigger or something) that I can use to alter a DateTime field when new data is inserted? The issue is that a service I am integrating with happens to send out all of its times (in this case the time some info was

  • XML Serialization is not including milliseconds in datetime field from Rails model 2010-03-08

    By default, the datetime field from the database is being converted and stripping off the milliseconds: some_datetime => "2009-11-11T02:19:36Z" attribute_before_type_cast('some_datetime') => "2009-11-11 02:19:36.145" If I try to overrride the a

  • DetailsView Update command doesn't update unless all of the fields are present! 2010-11-16

    I have a page that binds data from DB to a DetailsView. I want to use the auto-generated Update command. Everything went OK, and also updating was successful, but if I remove any field that I don't want to have chance to update, then the Update comma

  • how to NOT update a field Ruby on Rails 2010-12-01

    I'm a newbie in rails. how put a validated on password field. specified only on create and used an allow_blank method. but everytime i update it still creates a nil in the password field. any help? validates :password, :presence => { :on => :cr

  • Incrementing datetime field with an update statement 2011-04-20

    So I've got a table that contains a number of datetime fields, and I have to increment each date by 1 day as I descend the list. So the dates as they exist would be: 2011-04-19 2011-04-19 2011-04-19 2011-04-19 And I need to run a statement to make th

  • LotusScript Function Doesn't Update Field 2012-01-24

    I'm trying to get a document to be created for each instance of a string of dates. This however doesn't work as I'd hoped - the field doesn't update and the debugger doesn't show me anything at all. Can someone point me in the right direction with my

  • Datetime field synchronized with rails app displaying a number string in rhodes app 2012-03-07

    I am using Rhoconnect for synchronizing Rails and Rhodes app. The db structure includes a datetime field along with others. when i display these records on rhodes app, the date time field (created_at) is showing '1330520025' instead of date and time.

  • How to update only "hour" part in a datetime field in oracle? 2012-04-03

    Is there a way to update only Hour part in a DateTime field?? If not, how do I update the time part in Oracle? I tried this-> update tab_name set C_Name=to_date('04/03/2012 00:31:00','MM/DD/YYYY HH:MI:SS AM') where C_Name1=10484; didn't work as I'

  • Update hours in 24 hour datetime field in oracle database 2012-04-05

    I`m trying to update time in datetime field as UPDATE table_name SET col_name=to_DATE('04/02/2012 00:12:00','MM/DD/YYYY HH24:MI:SS') WHERE col_name1='rer'; After updating in db,The output is like this '04/02/2012 12:12:00' Extra 12 it's adding in Hou

  • Updating unused field after initial creation does not work rails 2012-04-10

    For reference, this is using Rails 3.0.9. I can't seem to figure out why, but I cannot update a field which was left blank at the initial creation of the object/row. If my model looks like this: name - string date - date message - string If I put inf

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.216 (s). 11 q(s)