Hi, i am missing something here.... @temp = Mymodel.find_by_contents("#{session[:searchstr]}") i now want to remove all the models that have a field called apprflg that is set to 1. @temp.delete_if {|key, value| key == ''0'' }] but how do i make it so key is talkking abuoot my field called apprflg? -- 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 -~----------~----~----~----~------~----~------~--~---
@temp.delete_if {|key, ''apprflg''| apprflg == ''1'' }] ? -- 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 -~----------~----~----~----~------~----~------~--~---
actually its this right? @temp.delete_if {|x| x.apprflg == 0} -- 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 13/05/2007, at 7:51 AM, mixplate wrote:> > i am missing something here.... > > @temp = Mymodel.find_by_contents("#{session[:searchstr]}")First of all, shed the quotes. You don''t need them: @temp = Mymodel.find_by_contents(session[:searchstr]) Second, you''re not getting all models matching your search string, you''re only getting one. You want: @temp = Mymodel.find_all_by_contents(session[:searchstr]) Third, rather than deleting the records from the array after finding them, just don''t find them in the first place: @temp = Mymodel.find(:all, :conditions => [''contents = ? AND apprflag <> 0'', session[:searchstr]) And finally, your variable naming is terrible! Don''t abbreviate! What the hell is an apprflag? :) Pete Yandell http://notahat.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 -~----------~----~----~----~------~----~------~--~---