Ruby on Rails Thursday, October 8, 2015


 I have a helper like this:

  def table_elements(qualifier, count)
    if qualifier
      yield
    else
      return ("<td></td>" * count).html_safe
    end
  end
 

Then if I do this, what I want to happen is if resp is not null then it yields the block, otherwise it
yields two empty table cells.

<%= table_elements(resp,2) do %>
  <td><%= resp.remittance_id %></td>
  <td><%= resp.availability_date %></td>
<% end %>


 Since I have read alot of rails books and blogs and never seen anything quite this odd, I suspect someone will suggest an alternate way of doing this but at the moment I can't think of anything different. This helper almost works the way intended, but for some reason 3 extra ending tags </td> are getting thrown into the beginning of the page ..


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a4aa90b8-cd44-451b-8b85-ecc477c3db9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment