Including a json object in Rails 3 views

Hi All,
I’m trying to embed a json object into one of views, and what used to
work in Rails 2.x now no longer works.

I’m generating the json code in my Staff model:
def schedule
appointments = Appointment.find(:all, :conditions => {:staff_id =>
self.id})
appointments.to_json(
:only =>
[:id,:start,:end,:title,:body,:repeat,:repeat_id,:mon_repeat,:tue_repeat,:wed_repeat,:thu_repeat,:fri_repeat,:sat_repeat,:sun_repeat])
end

In my view I’m doing the following:

Finally, the output is not in JSON format, but rather:

Does anyone know what I can do so that the JSON object is rendered so
that my javascript can read it?

Thanks.

in rails3 not use h to escape html.

so replaced this code:

with below

2010/3/22 MikeGBoston [email protected]

[email protected] . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


tommy xiao
E-mail: xiaods(AT)gmail.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs