1

I'm trying to use a block in a helper,

but that's giving me this error:

SyntaxError - syntax error, unexpected ')'
...rbout.concat(( green_title do ).to_s); _erbout.concat "\n   ...
...                               ^
(erb):4254: syntax error, unexpected end-of-input, expecting ')'
; _erbout.force_encoding(__ENCODING__)
                                      ^:
  (erb):1649:in `'

here's how I'm calling it:

  <%= green_title do %>
    text
  <% end %>

and here's my helper:

  def green_title(&block)
    capture do 
      concat content_tag(:h3) do
        yeld
      end
    end 
  end
Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
Don Giulio
  • 2,946
  • 3
  • 43
  • 82

1 Answers1

2

Your block is being associated with concat instead of content_tag

Try using parentheses to identify what belongs where.

concat(content_tag(:h3) do
  yield
end)
SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53
  • Thanks, I changed that, but still getting the same error, if I place a `byebug` in the helper it seems that the helper is not even called at any time. becaue of this I suspect the problem could be in the erb. In I remove the `=` from `<%=`, so have a non output tag the helper is called and I get this other error: `ArgumentError - wrong number of arguments (given 0, expected 1)` when calling the `capture` – Don Giulio Jun 23 '20 at 07:36