Hi all, Please help me solve the issue given below. Scenario: I''m fetching few rows from one table to a variable. Then I want to append that variable with another row of the same table, based on a condition. For that, I used push function with that variable, thinking the return type of Finder is array or hash. But, it gives me Undefined Method error. Code Snippet: #Controller @selected = Project.find(:all, :conditions => "id <= 4") @selected.push Project.find(:all, :conditions =>[''id >?'', params[:id]]) Please help me tackle this issue. This is for the functionality of drag & drop with two list. It would be very helpful, if you can give me a simple and complete example of the same as well. A prompt reply would be appreciated. Thanks, Tony Puthenveetil -- 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 -~----------~----~----~----~------~----~------~--~---
On 22 Jan 2009, at 13:54, Tony Puthenveettil wrote:> > Hi all, > > Please help me solve the issue given below. > > Scenario: > I''m fetching few rows from one table to a variable. Then I want to > append that variable with another row of the same table, based on a > condition. > > For that, I used push function with that variable, thinking the return > type of Finder is array or hash. But, it gives me Undefined Method > error. > > Code Snippet: > #Controller > @selected = Project.find(:all, :conditions => "id <= 4") > @selected.push Project.find(:all, :conditions =>[''id >?'', > params[:id]]) >push is almost certainly not what you want as it adds the argument at the end of the array (even if the argument is an array) for example: [1,2].push [3,4] #=> [1, 2, [3, 4]] whereas i expect you want to get [1,2,3,4] Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 22 Jan 2009, at 13:54, Tony Puthenveettil wrote: > >> For that, I used push function with that variable, thinking the return >> type of Finder is array or hash. But, it gives me Undefined Method >> error. >> >> Code Snippet: >> #Controller >> @selected = Project.find(:all, :conditions => "id <= 4") >> @selected.push Project.find(:all, :conditions =>[''id >?'', >> params[:id]]) >> > push is almost certainly not what you want as it adds the argument at > the end of the array (even if the argument is an array) > for example: > [1,2].push [3,4] #=> [1, 2, [3, 4]] > whereas i expect you want to get [1,2,3,4] > > FredDear Fred, You are there... right. Thanks for the information. Could anybody please help me append the data, explained above? -- 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 -~----------~----~----~----~------~----~------~--~---
Have a look at the documentation for Array, method ''+'' may be of interest. See http://www.ruby-doc.org/core/classes/Array.html 2009/1/23 Tony Puthenveettil <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > Frederick Cheung wrote: > > On 22 Jan 2009, at 13:54, Tony Puthenveettil wrote: > > > >> For that, I used push function with that variable, thinking the return > >> type of Finder is array or hash. But, it gives me Undefined Method > >> error. > >> > >> Code Snippet: > >> #Controller > >> @selected = Project.find(:all, :conditions => "id <= 4") > >> @selected.push Project.find(:all, :conditions =>[''id >?'', > >> params[:id]]) > >> > > push is almost certainly not what you want as it adds the argument at > > the end of the array (even if the argument is an array) > > for example: > > [1,2].push [3,4] #=> [1, 2, [3, 4]] > > whereas i expect you want to get [1,2,3,4] > > > > Fred > > > Dear Fred, You are there... right. Thanks for the information. > > Could anybody please help me append the data, explained above? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Colin Law wrote:> Have a look at the documentation for Array, method ''+'' may be of > interest. > See http://www.ruby-doc.org/core/classes/Array.html > > 2009/1/23 Tony Puthenveettil <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thanks Colin... -- 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 -~----------~----~----~----~------~----~------~--~---