Hi there fellows ! I''m currently working on a JSon view and had to make my own view (for simple ActiveSupport::JSON can''t do the trick anymore). The thing is, after my controller does this : respond_to format.html format.json end It does use the correct view in the correct context. Yet, the json view is filtered and the unsupported characters of HTML are modified. So this is pretty much what I get : {"created_at":"2011-07-28T15:38:36Z"} When all I really wanted was : {"created_at":"2011-07-28T15:38:36Z"} What''s up with that ? How may I prevent this filtering to happen ? -- Posted via http://www.ruby-forum.com/. -- 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 28, 5:53 pm, Michael José <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi there fellows ! > > I''m currently working on a JSon view and had to make my own view (for > simple ActiveSupport::JSON can''t do the trick anymore). > > The thing is, after my controller does this : > > respond_to > format.html > format.json > end > > It does use the correct view in the correct context. Yet, the json view > is filtered and the unsupported characters of HTML are modified. > > So this is pretty much what I get : > > {"created_at":"2011-07-28T15:38:36Z"} >You''re probably being tripped up by rails''s automatic html escaping What''s in your view file? It seems unlikely that you need to go down the root you''re going down - you can build whatever hash you need and then render it as json with render :json => some_hash. Fred> When all I really wanted was : > > {"created_at":"2011-07-28T15:38:36Z"} > > What''s up with that ? How may I prevent this filtering to happen ? > > -- > Posted viahttp://www.ruby-forum.com/.-- 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.
Well, the matter is quite complicated in fact. And I can''t happen to make render :json work for it does not render everything in an object (at least, not something you add via instance_variable_set. I have an object. This object is joint with another object. The two should be rendered in the same json object, but I figured that would not be possible, so I rendered an array, containing themselves an array with the first and the second object. In some case, some objects have children : I''d like to render the array of children in the same fashion (right after the object it concerns). I can''t think of a way to make that work without using a view. -- Posted via http://www.ruby-forum.com/. -- 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 29, 9:25 am, Michael José <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Well, the matter is quite complicated in fact. And I can''t happen to > make render :json work for it does not render everything in an object > (at least, not something you add via instance_variable_set. > > I have an object. > This object is joint with another object. > The two should be rendered in the same json object, but I figured that > would not be possible, so I rendered an array, containing themselves an > array with the first and the second object. > In some case, some objects have children : I''d like to render the array > of children in the same fashion (right after the object it concerns). > > I can''t think of a way to make that work without using a view.You may not be able to make render :json => my_active_record_object work, but (by definition) any piece of json is just a combination of hashes, arrays, strings, numbers etc. Build up that hash in ruby, call to_json on it and you should be away. Fred> > -- > Posted viahttp://www.ruby-forum.com/.-- 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.
Right, I guess I was kinda tired yesterday. Though, isn''t it cleaner to keep the "interface" stuff in the views ? Even if it''s json, it still is nothing but a view to the javascript part. Also, even if I stopped using the view, if someone was to get the same issue : the solution can be applying raw to the returns of ActiveSupport::JSON.encode ! -- Posted via http://www.ruby-forum.com/. -- 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.