Need help figuring out this code block...

Robert Malko wrote:

I posted this on the Ruby board but it may belong here.

Thanks!

<% @projects.each do |a| %>
  <% a.activities.each do |b| %>
    { period: '<%= b.win_at.strftime("%B, %d, %Y") %>', teaser: ['<%=
b.name %>'], label: ['']},
  <% end %>
<% end %>

You didn't tell us what was going wrong or what part of it is working
and what part not.

When I have trouble with something like this with some wacky syntax, I
like to hide as much of it inside other strings as possible to simplify
the line that is troublesome.

I would refactor that middle line into something like
<% front = "{ period: \'" %>
<% middle = "\', teaser: [\'" %>
<% back = "\'], label: [\'\']},"
<%= front + b.win_at.strftime(("%B, %d, %Y") + middle + b.name + back %>

its easier to follow, and it might either solve your problem or make it
easier to find it.

HTH,
jp