Displaying 1 result from an estimated 1 matches for "yixi5i21".
2005 Jul 09
0
ActiveRecord JSON Objects
Someone asked me in IRC if javascript can access ActiveRecord
properties. At first, this seemed like a silly request. But then I
remember JSON and thought, why can''t you?
I implemented a quick ActiveRecord -> JSON converter using the ruby-json gem.
http://rafb.net/paste/results/Yixi5I21.html
One problem was that I have to call .to_s to convert everything to a
format for JSON. But, objects like Time dont'' have nice .to_s
representations. So, I added an options hash that you can use to
override them.
@post.to_json(Time => [:to_s, :db]) will call .to_s(:db) on every t...