Hello Why this doesnt work? application_helper def check_collection(collection,partial_array,msg) if collection.empty? msg else partial_array.each do |partial| render :partial => partial end end end view <%=check_collection(@jobs,["job_list", "search_job"], "No job offers")%> I know that helper should return only last value, so it wont return 2 partials but it doesnt even display the last partial, only elements in an array. -- 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 you tried render :partial => partial_name, :collection => partial_array? I dunno that it''ll work in a helper but it''s the way to do what you''re doing outside of one. Might work inside as well. :) RSL On 3/9/07, Pablo <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello > > Why this doesnt work? > > application_helper > > def check_collection(collection,partial_array,msg) > if collection.empty? > msg > else > partial_array.each do |partial| > render :partial => partial > end > end > end > > > view > > <%=check_collection(@jobs,["job_list", "search_job"], "No job offers")%> > > I know that helper should return only last value, so it wont return 2 > partials but it doesnt even display the last partial, only elements in > an array. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> Have you tried render :partial => partial_name, :collection => > partial_array? I dunno that it''ll work in a helper but it''s the way to > do > what you''re doing outside of one. Might work inside as well. :) > > RSLThanks for na anwser but this doesnt seem to work also -- 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 -~----------~----~----~----~------~----~------~--~---
If you check what each method returns>> [1, 2].each {|n| n}=> [1, 2] You can understand why your code is not working. partial_array.inject('''') { |out, partial| out << (render :partial => partial)} may work but I''m not sure if is a good solution. Paolo On 09/03/07, Pablo <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello > > Why this doesnt work? > > application_helper > > def check_collection(collection,partial_array,msg) > if collection.empty? > msg > else > partial_array.each do |partial| > render :partial => partial > end > end > end > > > view > > <%=check_collection(@jobs,["job_list", "search_job"], "No job offers")%> > > I know that helper should return only last value, so it wont return 2 > partials but it doesnt even display the last partial, only elements in > an array. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Paolo Negri wrote:> If you check what each method returns > >>> [1, 2].each {|n| n} > => [1, 2] > > You can understand why your code is not working. > > partial_array.inject('''') { |out, partial| out << (render :partial => > partial)} > > may work but I''m not sure if is a good solution. > > PaoloThis works fine! Thx -- 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 -~----------~----~----~----~------~----~------~--~---
> def check_collection(collection,partial_array,msg) > if collection.empty? > msg > else > partial_array.each do |partial| > render :partial => partial > end > end > endyou can create a string (str_output for example) and then do something like str_output+= render_to_string (:partial=>partial) finally put at the end of the helper "str_output", so that will be your return value. regards, javier ramirez - -------- Estamos de estreno... si necesitas llevar el control de tus gastos visita http://www.gastosgem.com !!Es gratis!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---