Hello,

I'm having a hard time understanding how you are supposed to write
helpers that take blocks now in Rails 3.

According to 7.4.2 here:

   http://edgeguides.rubyonrails.org/3_0_release_notes.html

you are supposed to write your helpers to return their result as text,
rather than append to the accumulating content.

How do I execute the code in the block that has been passed to the
helper without it appending to the content? My instincts, which are
clearly wrong, are to just use "yield" like I would in any other method
that takes a block. However, within the context of a helper method.
"yield" seems to have a side effect of appending to the accumulating
content. So, I have to do the following to suppress the intended output
of the helper because the yield is already appending it:

module FooHelper
  def none_if_empty
    yield
    return ''
  end
end

What is the proper way to write this helper in Rails 3?

Thanks,
Avram
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to