How to build JSON formatted data structures like XML''s are done with rxml templates? I can''t use to_json method because I need other formatting than object''s one... probably I should play with strings within html.erb templates if there isn''t any better solution or JSON builder? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
blackflash wrote:> How to build JSON formatted data structures like XML''s are done with > rxml templates? > > I can''t use to_json method because I need other formatting than > object''s one... probably I should play with strings within html.erb > templates if there isn''t any better solution or JSON builder?I found this link which may help you. http://blog.tagteaminteractive.com/2008/01/28/sexy-rest-in-rails/ -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hims Khurana wrote:> blackflash wrote: >> How to build JSON formatted data structures like XML''s are done with >> rxml templates? >> >> I can''t use to_json method because I need other formatting than >> object''s one... probably I should play with strings within html.erb >> templates if there isn''t any better solution or JSON builder? > > I found this link which may help you. > > http://blog.tagteaminteractive.com/2008/01/28/sexy-rest-in-rails/The link was broken; but can be referred to at the Way Back Time Machine: http://web.archive.org/web/20080205212821/http://blog.tagteaminteractive.com/ Also, snippet below... def render(opts = {}, &block) if opts[:to_yaml] then headers["Content-Type"] = "text/plain;" render :text => Hash.from_xml(render_to_string(:template => opts[:to_yaml], :layout => false)).to_yaml, :layout => false elsif opts[:to_json] then # headers["Content-Type"] = "text/javascript;" render :json => Hash.from_xml(render_to_string(:template => opts[:to_json], :layout => false)).to_json, :layout => false else super opts, &block end end respond_to do |wants| wants.html wants.xml { render :layout => false } wants.yaml { render :to_yaml => "nodes/show.xml.builder" } wants.json { render :to_json => "nodes/show.xml.builder" } end -- Posted via http://www.ruby-forum.com/.
it''s not exactly like rxml but should do the job: https://github.com/inem/tequila -- 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.