0

I have section of code that works when placed in the view, but fails to render when the code is moved to a helper. I know the code is executing because the server shows the render call, but there is no output to the browser.

This works (when placed in the view file)

<% vidList = "ylLzyHk54Z0", "ylLzyHk54Z0", "ylLzyHk54Z0", "ylLzyHk54Z0" %>
<% i=1 %>
<% vidList.each do |v| %>
  <%= render partial: 'loadvid', locals: {vidId: i.to_s, divId: "vid"+i.to_s, vidURL: v } %>
  <% i=i+1 %>
<% end %>

This does not.

module VidsHelper
  def loadvids(vidList)
    i=1
    vidList.each do |v|
      render partial: 'loadvid', locals: {vidId: i.to_s, divId: "vid"+i.to_s, vidURL: v }
      i=i+1
    end
  end
end

As I said, I know the method is being called because the server reports that _loadvid.html.erb was rendered 4 times. It is being called with

<% vidList = "ylLzyHk54Z0", "ylLzyHk54Z0", "ylLzyHk54Z0", "ylLzyHk54Z0" %>
<% loadvids vidList %>

When I view source in the browser absolutely nothing is being rendered.

Joe Kennedy
  • 9,365
  • 7
  • 41
  • 55

1 Answers1

0

As far as I can tell, any call within <% %> will not display. Calling the function within <%= %>, however, shows the output of the method, not the render output. The only solution I can see is to capture the render output and then re-render it. The current working code is this:

In the view:

  <%= render inline: loadvids(vidList) %>

In the helper:

def loadvids (vidList)
    i=1
    capture = []
    vidList.each do |v|
        capture.push render partial: "loadvid", locals: {vidId: i.to_s, divId: "vid"+i.to_s, vidURL: v }
        i=i+1
    end
    capture.join
end