hi, i am using http://arshaw.com/fullcalendar/ to display a calendar. It uses json to populate the calendar events. The JSON looks like this events: [ { title: ''All Day Event'', start: new Date(y, m, 1) }, { title: ''Long Event'', start: new Date(y, m, d-5), end: new Date(y, m, d-2) }, { id: 999, title: ''Repeating Event'', start: new Date(y, m, d-3, 16, 0), allDay: false } ] A date looks like Fri Jul 29 2011 22:54:08 GMT-0400 (EDT) When i select from my events table i run: @member_calendars = Member::Calendar.find_by_sql("SELECT * from calendars") @json_calendar = ActiveSupport::JSON.encode(@member_calendars) How can i get my dates into a format that works for this json object? Also, how would i pull my json object into the view so i can play with it in javascript. The following code treats my json object as a string: var foo = ''<%= @json_calendar %>''; $.each(foo, function(i, item) { alert(i); }); It will alert each and every character from my object -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 30, 3:57 am, jdkealy <jdke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > A date looks like Fri Jul 29 2011 22:54:08 GMT-0400 (EDT) > > When i select from my events table i run: > @member_calendars = Member::Calendar.find_by_sql("SELECT * from > calendars") > @json_calendar = ActiveSupport::JSON.encode(@member_calendars) > > How can i get my dates into a format that works for this json object?Looks like that calendar plugin would be happy with iso8601 dates, which is what rails should generate by default when encoding dates as json> > Also, how would i pull my json object into the view so i can play with > it in javascript. > > The following code treats my json object as a string: > > var foo = ''<%= @json_calendar %>'';You asked for it to be a string - you''ve enclosed it in quotes Fred> $.each(foo, function(i, item) { > alert(i); > }); > > It will alert each and every character from my object-- 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.
when i try this without quotes, all my javascript breaks. On Jul 30, 10:47 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 30, 3:57 am,jdkealy<jdke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > A date looks like Fri Jul 29 2011 22:54:08 GMT-0400 (EDT) > > > When i select from my events table i run: > > @member_calendars = Member::Calendar.find_by_sql("SELECT * from > > calendars") > > @json_calendar = ActiveSupport::JSON.encode(@member_calendars) > > > How can i get my dates into a format that works for this json object? > > Looks like that calendar plugin would be happy with iso8601 dates, > which is what rails should generate by default when encoding dates as > json > > > > > Also, how would i pull my json object into the view so i can play with > > it in javascript. > > > The following code treats my json object as a string: > > > var foo = ''<%= @json_calendar %>''; > > You asked for it to be a string - you''ve enclosed it in quotes > > Fred > > > > > > > > > $.each(foo, function(i, item) { > > alert(i); > > }); > > > It will alert each and every character from my object-- 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.
On Jul 30, 4:17 pm, jdkealy <jdke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> when i try this without quotes, all my javascript breaks. >probably worth looking at what''s wrong then. Fred> On Jul 30, 10:47 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On Jul 30, 3:57 am,jdkealy<jdke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > A date looks like Fri Jul 29 2011 22:54:08 GMT-0400 (EDT) > > > > When i select from my events table i run: > > > @member_calendars = Member::Calendar.find_by_sql("SELECT * from > > > calendars") > > > @json_calendar = ActiveSupport::JSON.encode(@member_calendars) > > > > How can i get my dates into a format that works for this json object? > > > Looks like that calendar plugin would be happy with iso8601 dates, > > which is what rails should generate by default when encoding dates as > > json > > > > Also, how would i pull my json object into the view so i can play with > > > it in javascript. > > > > The following code treats my json object as a string: > > > > var foo = ''<%= @json_calendar %>''; > > > You asked for it to be a string - you''ve enclosed it in quotes > > > Fred > > > > $.each(foo, function(i, item) { > > > alert(i); > > > }); > > > > It will alert each and every character from my object-- 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.