Hi guys, I must be missing something obvious, but I can''t get my head around this: In a view, if I do: <% for i in 1..3 %> <%= render :partial => ''test'' %> <% end %> (note: _test just displays a string) it works just fine. But if I move this into the corresponding helper: <%= test_helper() %> with (in the helper): def test_helper for i in 1..3 render :partial => ''test'' end end it displays in my page: 1..3 as if test_helper had returned the string "1..3". Any idea what is wrong with this code? Thanks a lot! Peter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2009-Dec-10 22:18 UTC
Re: Problem rendering several partials from an helper
On Dec 10, 10:15 pm, PierreW <wamre...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > def test_helper > for i in 1..3 > render :partial => ''test'' > end > end > > it displays in my page: > 1..3 > as if test_helper had returned the string "1..3".Which is exactly what it returned - for x in y; end evaluates to y. You''re rendering partials but then discarding the results. You need to be hanging onto the results of the renders and joining them together (and then return that) Fred> > Any idea what is wrong with this code? > > Thanks a lot! > Peter-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks a lot Fred. That was it. Peter. On Dec 10, 10:18 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 10, 10:15 pm, PierreW <wamre...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > def test_helper > > for i in 1..3 > > render :partial => ''test'' > > end > > end > > > it displays in my page: > > 1..3 > > as if test_helper had returned the string "1..3". > > Which is exactly what it returned - for x in y; end evaluates to y. > You''re rendering partials but then discarding the results. You need to > be hanging onto the results of the renders and joining them together > (and then return that) > > Fred > > > > > > > Any idea what is wrong with this code? > > > Thanks a lot! > > Peter-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.