Setting the datetime format in output

22 views
Skip to first unread message

JP Slavinsky

unread,
Nov 9, 2014, 7:40:14 PM11/9/14
to roar...@googlegroups.com
Howdy - I want my representers to output datetimes in a specific format.  Is there a mechanism in representable/roar that is best suited for this?  If not, suggestions on the easiest (least code) way to make this happen?  I tried to go down a virtus/coercion path, but didn't have much luck.

Thanks, JP


Nick Sutterer

unread,
Nov 9, 2014, 7:43:12 PM11/9/14
to roar...@googlegroups.com
Hey JP,

override the reader method for that particular date property in your representer.

def created_at
  super.to_s("%format")
end

Nick

On Mon, Nov 10, 2014 at 11:40 AM, JP Slavinsky <j...@kindlinglabs.com> wrote:
Howdy - I want my representers to output datetimes in a specific format.  Is there a mechanism in representable/roar that is best suited for this?  If not, suggestions on the easiest (least code) way to make this happen?  I tried to go down a virtus/coercion path, but didn't have much luck.

Thanks, JP


--
You received this message because you are subscribed to the Google Groups "Roar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roar-talk+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JP Slavinsky

unread,
Nov 9, 2014, 7:59:51 PM11/9/14
to roar...@googlegroups.com
Thanks Nick.

You received this message because you are subscribed to a topic in the Google Groups "Roar" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/roar-talk/M6RtchUP5wg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to roar-talk+...@googlegroups.com.

Nick Sutterer

unread,
Nov 9, 2014, 8:00:07 PM11/9/14
to roar...@googlegroups.com
You're welcome, JP. 
360.gif

Nick Sutterer

unread,
Nov 9, 2014, 8:01:32 PM11/9/14
to roar...@googlegroups.com
BTW, you can also override the :getter option, but I personally prefer using as less options as possible.

property :created_at, getter: -> { represented.created_at.to_s("...") }
360.gif
Reply all
Reply to author
Forward
0 new messages