Yeah.. I was basically wonder what the best practice / preferred
method for this was.

When using ajax and json to update a page with a new object that
includes a date.. (like created_at) and you want that date to be only
month and day.. Do you parse the date on the server side and send over
as string (Is that possible with to_json?) or do you send over the
default ISO format and do the conversion on the client side in
javascript.

I'd like to do it on the server side, but then the only way I can see
is a complete hack around by adding another method to the ActiveRecord
class.

def created_at_formatted
 self.created_at.to_S('md')
end

object.to_json( :methods => [:created_at_formatted] )

-tim

On Aug 19, 9:19 am, Robert Walker <[email protected]>
wrote:
> Tim W. wrote:
> > How does one format a time when serializing an active record object?
>
> I'm not sure I quite follow your question, but I do know that the
> to_json method as implemented in Rails uses the same date and time
> formats as does to_xml.
>
> Example:
> "2009-08-19T13:03:07Z"
>
> > Server side somehow or leave it up to client side javascript?
>
> In the case of to_json the serialization of date and time gets formatted
> as a string on the server-side. I assume if you were to use that data in
> JavaScript (client-side) you would need to parse the string date/time
> format to a JavaScript Date object. I'm sure you could find a JS code
> snippet to handle that.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to