Quantcast
Channel: Dave Copeland :ruby:
Viewing all articles
Browse latest Browse all 591

Article 2

$
0
0

You want do write

def form_form(x,&block)
"<form action=‘#{x.path}’ “>#{ yield }</form>”
end

but you can't with Erubi. You must do this:

def form_for(x,&block)
b = block.binding.local_variable_get("_buf”)
b << "<form>"
block.()
b << "</form>"
""
end

i.e. access the local variable into which code is being placed and manipulate it.

Rails special-cases code that looks like a block and omits the parens. But it's a lot to make that happen properly.


Viewing all articles
Browse latest Browse all 591