Hey guys,
There is something I have been trying to implement but so far no luck.
Basically, I want to have helpers that generate HTML around given
content, similar to ActionView’s form_for. Besides, I want to keep
that “framing” HTML in separate files, similar to templates.
Ideally I’d even love to suggest it as a feature for Rails. Let me
show you an example.
This is what I want to have in my rhtml file:
<% bubble_block :corners => “round”, :color => “brown” do %>
So far I have tried the following: I added a method to my application
helper:
def bubble_block(options, &proc)
raise ArgumentError, “No block given” unless block_given?
rendered_html = render(:partial => “/templates/bubble”, :locals =>
{:block => proc} )
concat rendered_html, proc.binding
end
This is how _bubble.rhtml looks like:
What happens is ALMOST what I want, except my block gets rendered
twice. The output looks like this:
What am I missing? Thank you!