I use rabl 0.11.6 for my API, and I find that I am doing the following over and over for each date or time object:
node :created_at do |article|
article.created_at.iso8601
end
This will save a lot of duplicate code if the format for each date object can be set in one place, so I could just use a method attributeslike this
attributes :created_at
I found a problem with github ( https://github.com/ccocchi/rabl-rails/issues/68 ) where they suggest overwriting some Oj.default_options = { mode: :compat, time_format: :ruby }in the initializer. But I have no idea how to do it .iso8601.
Then I found this https://gist.github.com/astevens/b80225d96d8889c946ac . But this looks like a hacker solution for monkey patches.
And finally, I found this problem https://github.com/nesquena/rabl/issues/336 , where they rewrite the method as_jsonfrom ActiveSupport::TimeWithZone, is also a very monkey-patch solution.
Is there no way to tell RABL which date and time format to use? And if not, what would be the best / least-hacked method to achieve this?
23tux source
share