I''m ecpecting this to return json format even when the request would be expected to return in html. the output looks like this! [{"controller": "page", "item": 1, "name": "Home", "id": 2, "action": "show", "submenus": 0}, {"controller": "contact", "item": null, "name": "Account", "id": 5, "action": null, "submenus": 3}, {"controller": null, "item": null, "name": "Admin", "id": 3, "action": null, "submenus": 4}, {"controller": "page", "item": 2, "name": "About", "id": 4, "action": "show", "submenus": 0}] Which doesn;t look like json to me!! :> def getmenu if params[:id] == ''0'' menus=Menu.find(:first, :conditions => "name=''root''").children else menus=Menu.find(:all, :conditions => "parent_id=''#{params[:id]}''") end menu=[] menus.each do |m| menu[m.position]={:name => m.name, :controller => m.controller, :action => m.action, :item => m.item, :id => m.id, :submenus => m.children.size} end output=menu.compact.to_json respond_to do |format| format.html { render :json => output } format.json { render :json => output } end end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Looks like JSON to me. If anything it''s just missing a top-level identifier, but what''s there I think is valid (to_json created it after all). Jason On Feb 5, 2008 1:42 PM, spokra <spokra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m ecpecting this to return json format even when the request would > be expected to return in html. the output looks like this! > > [{"controller": "page", "item": 1, "name": "Home", "id": 2, "action": > "show", "submenus": 0}, {"controller": "contact", "item": null, > "name": "Account", "id": 5, "action": null, "submenus": 3}, > {"controller": null, "item": null, "name": "Admin", "id": 3, "action": > null, "submenus": 4}, {"controller": "page", "item": 2, "name": > "About", "id": 4, "action": "show", "submenus": 0}] > > Which doesn;t look like json to me!! :> > > > def getmenu > if params[:id] == ''0'' > menus=Menu.find(:first, :conditions => "name=''root''").children > else > menus=Menu.find(:all, :conditions => > "parent_id=''#{params[:id]}''") > end > menu=[] > menus.each do |m| > menu[m.position]={:name => m.name, > :controller => m.controller, > :action => m.action, > :item => m.item, > :id => m.id, > :submenus => m.children.size} > end > output=menu.compact.to_json > respond_to do |format| > format.html { render :json => output } > format.json { render :json => output } > end > end > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Actually that is exactly what JSON looks like...what were you expecting? -- 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 -~----------~----~----~----~------~----~------~--~---