Hi, I''m having problems using the jsonifier plugin (I''m not using edge) but I''m having trouble using :only, and :except. If I do I get an ArgumentError wrong number of arguments (1 for 0). Here is my code: def tutorialData @tutorialData = Tutorial.find(:all) render :text => @tutorialData.to_json(:only => :created_at), :layout => false end Any suggestions would be much appreciated. Thanks, Tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi fernando, i don''t know how jsoinifer plugin works, but after installing this, if you are expecting it to override the default to_json method(provided by rails), then the code which you posted here is perfect, but if that plugin is not overriding the to_json method of rails then the code which you posted here is wrong, as you know (default)to_json method won''t accept any kind of argument. this is what i know, sorry if it''s not answering your question. Good luck., On Sep 28, 3:25 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m having problems using the jsonifier plugin (I''m not using edge) > but I''m having trouble using :only, and :except. > If I do I get an ArgumentError wrong number of arguments (1 for 0). > Here is my code: > > def tutorialData > @tutorialData = Tutorial.find(:all) > render :text => @tutorialData.to_json(:only > => :created_at), :layout => false > end > > Any suggestions would be much appreciated. > > Thanks, > > Tim--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Cheers for that. The plugin works in some respects, removing the ''attributes'' from every json object. So iI assume that means that rails has found it and it is working but I still can''t pass any arguemtns??? One post here: report that: This gets me past the wrong number of arguments error: format.json { render(:json => @customers.collect { |customer| customer.to_json(:only => :name) } ) } But I''m not exactly sure whats going on in that code. once agian, any help would be much appreciated. On Sep 28, 3:43 pm, raghukumar <raghukumar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi fernando, > > i don''t know how jsoinifer plugin works, > but after installing this, if you are expecting it to override the > default to_json method(provided by rails), > then the code which you posted here is perfect, but if that plugin is > not overriding the to_json method of rails > then the code which you posted here is wrong, as you know > (default)to_json method won''t accept any kind of argument. > > this is what i know, sorry if it''s not answering your question. > > Good luck., > > On Sep 28, 3:25 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I''m having problems using the jsonifier plugin (I''m not using edge) > > but I''m having trouble using :only, and :except. > > If I do I get an ArgumentError wrong number of arguments (1 for 0). > > Here is my code: > > > def tutorialData > > @tutorialData = Tutorial.find(:all) > > render :text => @tutorialData.to_json(:only > > => :created_at), :layout => false > > end > > > Any suggestions would be much appreciated. > > > Thanks, > > > Tim--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sounds like you just want to customise your json output. So why not do the following? def to_json { :column_name => column_name, :some_other_name => another_column_name }.to_json end This gives you the advantage of a layer of abstraction between your JS code and Rails code, so if your column names change, you needn''t change your JavaScript. On Sep 29, 10:58 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Cheers for that. The plugin works in some respects, removing the > ''attributes'' from every json object. So iI assume that means that > rails has found it and it is working but I still can''t pass any > arguemtns??? One post here: > > report that: > This gets me past the wrong number of arguments error: > format.json { render(:json => @customers.collect { |customer| > customer.to_json(:only => :name) } ) } > > But I''m not exactly sure whats going on in that code. > > once agian, any help would be much appreciated. > > On Sep 28, 3:43 pm, raghukumar <raghukumar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi fernando, > > > i don''t know how jsoinifer plugin works, > > but after installing this, if you are expecting it to override the > > default to_json method(provided by rails), > > then the code which you posted here is perfect, but if that plugin is > > not overriding the to_json method of rails > > then the code which you posted here is wrong, as you know > > (default)to_json method won''t accept any kind of argument. > > > this is what i know, sorry if it''s not answering your question. > > > Good luck., > > > On Sep 28, 3:25 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > I''m having problems using the jsonifier plugin (I''m not using edge) > > > but I''m having trouble using :only, and :except. > > > If I do I get an ArgumentError wrong number of arguments (1 for 0). > > > Here is my code: > > > > def tutorialData > > > @tutorialData = Tutorial.find(:all) > > > render :text => @tutorialData.to_json(:only > > > => :created_at), :layout => false > > > end > > > > Any suggestions would be much appreciated. > > > > Thanks, > > > > Tim--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes customising my JSON output is exactly what I want to do. I only want to pass certain columns (I have a very simple example to output category names) . I tried your suggestion by putting: def to_json { :name => ''name'' }.to_json end Into my model and : def tutorialData @tutorialData = Category.find(:all) render :text => @tutorialData.to_json( :name), :layout => false end into my controller but I still get a "wrong number of arguments (1 for 0)". Sorry if I am missing something quite fundamental but it looks like rails still expects 0 arguments for the .to_json method?? many thanks for your help so far On Sep 29, 11:28 am, andrewbruce <bruciemo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sounds like you just want to customise your json output. So why not do > the following? > > def to_json > { > :column_name => column_name, > :some_other_name => another_column_name > }.to_json > end > > This gives you the advantage of a layer of abstraction between your JS > code and Rails code, so if your column names change, you needn''t > change your JavaScript. > > On Sep 29, 10:58 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Cheers for that. The plugin works in some respects, removing the > > ''attributes'' from every json object. So iI assume that means that > > rails has found it and it is working but I still can''t pass any > > arguemtns??? One post here: > > > report that: > > This gets me past the wrong number of arguments error: > > format.json { render(:json => @customers.collect { |customer| > > customer.to_json(:only => :name) } ) } > > > But I''m not exactly sure whats going on in that code. > > > once agian, any help would be much appreciated. > > > On Sep 28, 3:43 pm, raghukumar <raghukumar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi fernando, > > > > i don''t know how jsoinifer plugin works, > > > but after installing this, if you are expecting it to override the > > > default to_json method(provided by rails), > > > then the code which you posted here is perfect, but if that plugin is > > > not overriding the to_json method of rails > > > then the code which you posted here is wrong, as you know > > > (default)to_json method won''t accept any kind of argument. > > > > this is what i know, sorry if it''s not answering your question. > > > > Good luck., > > > > On Sep 28, 3:25 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > > > I''m having problems using the jsonifier plugin (I''m not using edge) > > > > but I''m having trouble using :only, and :except. > > > > If I do I get an ArgumentError wrong number of arguments (1 for 0). > > > > Here is my code: > > > > > def tutorialData > > > > @tutorialData = Tutorial.find(:all) > > > > render :text => @tutorialData.to_json(:only > > > > => :created_at), :layout => false > > > > end > > > > > Any suggestions would be much appreciated. > > > > > Thanks, > > > > > Tim--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I defined the to_json method with 0 arguments, so would expect to get that error. The ''name'' comes straight from the object. So: def to_json { :name => name # note: no quotation marks }.to_json end and def tutorialData @tutorialData = Category.find(:all) render :json => @tutorialData.to_json end Should do it. On Sep 29, 12:15 pm, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes customising my JSON output is exactly what I want to do. > I only want to pass certain columns (I have a very simple example to > output category names) . I tried your suggestion by putting: > def to_json > { > :name => ''name'' > }.to_json > end > Into my model and : > > def tutorialData > @tutorialData = Category.find(:all) > render :text => @tutorialData.to_json( :name), :layout => false > end > > into my controller but I still get a "wrong number of arguments (1 > for 0)". > Sorry if I am missing something quite fundamental but it looks like > rails still expects 0 arguments for the .to_json method?? > > many thanks for your help so far > > On Sep 29, 11:28 am, andrewbruce <bruciemo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Sounds like you just want to customise your json output. So why not do > > the following? > > > def to_json > > { > > :column_name => column_name, > > :some_other_name => another_column_name > > }.to_json > > end > > > This gives you the advantage of a layer of abstraction between your JS > > code and Rails code, so if your column names change, you needn''t > > change your JavaScript. > > > On Sep 29, 10:58 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Cheers for that. The plugin works in some respects, removing the > > > ''attributes'' from every json object. So iI assume that means that > > > rails has found it and it is working but I still can''t pass any > > > arguemtns??? One post here: > > > > report that: > > > This gets me past the wrong number of arguments error: > > > format.json { render(:json => @customers.collect { |customer| > > > customer.to_json(:only => :name) } ) } > > > > But I''m not exactly sure whats going on in that code. > > > > once agian, any help would be much appreciated. > > > > On Sep 28, 3:43 pm, raghukumar <raghukumar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi fernando, > > > > > i don''t know how jsoinifer plugin works, > > > > but after installing this, if you are expecting it to override the > > > > default to_json method(provided by rails), > > > > then the code which you posted here is perfect, but if that plugin is > > > > not overriding the to_json method of rails > > > > then the code which you posted here is wrong, as you know > > > > (default)to_json method won''t accept any kind of argument. > > > > > this is what i know, sorry if it''s not answering your question. > > > > > Good luck., > > > > > On Sep 28, 3:25 am, fernando <tim.fernandezh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, > > > > > > I''m having problems using the jsonifier plugin (I''m not using edge) > > > > > but I''m having trouble using :only, and :except. > > > > > If I do I get an ArgumentError wrong number of arguments (1 for 0). > > > > > Here is my code: > > > > > > def tutorialData > > > > > @tutorialData = Tutorial.find(:all) > > > > > render :text => @tutorialData.to_json(:only > > > > > => :created_at), :layout => false > > > > > end > > > > > > Any suggestions would be much appreciated. > > > > > > Thanks, > > > > > > Tim--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---