erik-megarad / negative-captcha

A plugin to make the process of creating a negative captcha in Rails much less painful
MIT License
791 stars 72 forks source link

Can't pass block to negative_label_tag #15

Closed triemstr closed 9 years ago

triemstr commented 12 years ago

I tried to convert this:

<label class="desc" id="title8" for="Field8">
  Email
  <span id="req_8" class="req">*</span>
</label>

to this:

<%= negative_label_tag @captcha, :Field8, 'Email', :id => 'title8', :class => 'desc' do %>
  <span id="req_8" class="req">*</span>
<% end %>

And the "span" block completely disappears. If I do a regular label_tag it works just fine.

Any chance this can be improved to allow blocks?

Thanks greatly. Kevin

lime commented 10 years ago

+1 to this. I was surprised to notice that this is not possible.

I'd like to have a go at it myself, I just fear that time and skill will be in the way. :)

lime commented 9 years ago

This bit me again, but I came up with a workaround. ActionView::Helpers::CaptureHelper#capture to the rescue!

For example, @triemstr's code above could be written as:

<% label_contents = capture do %>
  Email
  <span id="req_8" class="req">*</span>
<% end %>
<%= negative_label_tag @captcha, :Field8, label_contents, :id => 'title8', :class => 'desc' %>

Of course it would be much better if the view helpers accepted blocks, but at least there is a way to deal with the current situation.