The docs say this about content_tag:
==
Returns an HTML block tag of type name surrounding the content.
==
Ok, not too helpful unless you understand the subtleties of css/html
speak. But the docs provide some examples that should help clarify
things:
content_tag(:p, "Hello world!")
# => <p>Hello world!</p>
Presumably, the html is a String--the return value doesn't look like a
number or a method.
As for how blocks work: a block is really just a function. You write a
block in your code immediately after calling a method, and the method
captures the block in a variable. Then at some point the method calls
the block. Here is an example:
def some_method(str, &func)
if block_given?
puts func.call(str)
else
puts str
end
end
some_method("John") do |name|
"Hello #{name}"
end
--output:--
Hello John
The block is this part:
do |name|
"Hello #{name}"
end
which can also be written as:
{ |name| "Hello #{name"}
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.