Topic: Anyone using JSON?

I'm told it's now built in to Rails but I can't find much on it yet - well, lots on json but not much on how it's used in Rails.

Anyone using it at the moment who could share some thoughts on best practice?

Re: Anyone using JSON?

Nobody at all?

Re: Anyone using JSON?

All I know is that prototype uses it some and there's a "to_json" method defined in Object. I believe it's useful for passing values into javascript functions. You may want to do a search for json in the Rails source code and see how they use it.

Railscasts - Free Ruby on Rails Screencasts

Re: Anyone using JSON?

I was planning to use it in a wiki where I could just use Javascript to go get data from a Rails application and build tables of data realtime in the wiki page.  Sounded like it should work but I can't find any documentation on what is built into Rails JSON and nothing at all on cool uses.  My normal development process is google, cut and paste (GCP(tm)) and it really doesn't help when the first bit doesn't work!

Re: Anyone using JSON?

I would just try playing around with the to_json method. You can fetch some ActiveRecord objects and call to_json on that.

def my_action
  render :text => MyModel.find(:all).to_json
end

After that, you just have to worry about the Javascript side on fetching the text, parsing it and updating the page.

Railscasts - Free Ruby on Rails Screencasts