Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:38:22+00:00 2026-06-11T16:38:22+00:00

I am using active_model_serializers and ember.js. One of my models has a date attribute.

  • 0

I am using active_model_serializers and ember.js. One of my models has a date attribute. In rails date attributes are serialized in the format of “YYYY-MM-DD”.

The problem; when ember-data de-serializes the date using the javascript Date constructor it assumes an “incorrect” timezone.

*Incorrect is not the best word but it is incorrect because I want it to default to the current timezone. DS.Model date attribute parses date (YYYY-MM-DD) incorrectly

I am thinking the active_model_serializer should take the date attribute and convert it to iso8601 format.

 Object.date.to_time_in_current_zone.iso8601

Is there a way to tell active_model_serializers how to serialize all date objects? Or should I be fixing the timezone issue in javascript?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:38:24+00:00Added an answer on June 11, 2026 at 4:38 pm

    Here is my current solution but I really feel it should be possible to define how date objects get serialized globally.

    class InvoiceSerializer < ActiveModel::Serializer
      attributes :id, :customer_id, :balance
    
      def attributes
        hash = super
        hash['date'] = object.date.to_time_in_current_zone.iso8601 if object.date
        hash
      end
    end
    

    UPDATE

    My preferred solution now is to monkey patch the ActiveSupport::TimeWithZone.as_json method.

    #config/initializers/time.rb
    module ActiveSupport
      class TimeWithZone
        def as_json(options = nil)
          time.iso8601
        end
      end
    end
    
    class InvoiceSerializer < ActiveModel::Serializer
      attributes :id, :customer_id, :balance, :date
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using active_model_serializers to render a collection as JSON for ember-data consumption. All
Has anyone been able to get access to Active Directory using Entity Data Model?.
I'm using Rails 3 w/ Mongoid, (so no ActiveRecord). Mongoid uses ActiveModel's to_json method,
As I know ruby on rails are using Active Record with table per class
I'm using Active Record outside of rails and I have two AR classes similar
Using DCS I am trying to deserialize objects from XML where the object serialized
Using Rails 3 validations and/or callbacks, what would be the cleanest way to ensure
I have a rails app that is is using cancan permission and i am
I am using CI, however this question applies to models and db persistence in
Im using rails 3.2 and am having trouble using pre-created devise alongside active admin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.