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:
<script type="text/javascript">
var schedule = <%= h @staff.schedule.to_json %>;
</script>
Finally, the output is not in JSON format, but rather:
<script type="text/javascript">
var schedule
"[{\"title\":\"available\",\"repeat_id\":null,\"body\":\"\",\"wed_repeat\":false,\"tue_repeat\":false,\"thu_repeat\":false,\"repeat\":false,\"id\":1,\"end\":\"2010-03-23T21:30:00Z\",\"start\":\"2010-03-23T21:00:00Z\",\"sun_repeat\":false,\"mon_repeat\":false,\"sat_repeat\":false,\"fri_repeat\":false}]";
</script>
Does anyone know what I can do so that the JSON object is rendered so that
my javascript can read it?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.