# Including a json object in Rails 3 views

**URL:** <https://www.ruby-forum.com/t/including-a-json-object-in-rails-3-views/185540>\
**Category:** Rails\
**Created:** [March 22, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/including-a-json-object-in-rails-3-views/185540 "2010-03-22T13:51:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeGBoston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@MikeGBoston](https://www.ruby-forum.com/u/MikeGBoston)\
**Post date:** [March 22, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/including-a-json-object-in-rails-3-views/185540/1 "2010-03-22T13:51:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MikeGBoston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@MikeGBoston](https://www.ruby-forum.com/u/MikeGBoston)\
**Post date:** [March 22, 2010, 2:33pm UTC](https://www.ruby-forum.com/t/including-a-json-object-in-rails-3-views/185540/2 "2010-03-22T14:33:57Z")

</div>

in rails3 not use h to escape html.

so replaced this code:

with below

2010/3/22 MikeGBoston [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> removed\_email\_address@domain.invalid . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

–  
tommy xiao  
E-mail: xiaods(AT)[gmail.com](http://gmail.com)
