Answer the question
In order to leave comments, you need to log in
How to write a method with "do" in Ruby?
How to write an analog to this?
<%= content_tag :div, class: "strong" do %>
Hello world!
<% end %>
Answer the question
In order to leave comments, you need to log in
As far as I remember, it's &block.
// EDIT
apidock.com/rails/ActionView/Helpers/TagHelper/con...
# File actionview/lib/action_view/helpers/tag_helper.rb, line 103
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
if block_given?
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
content_tag_string(name, capture(&block), options, escape)
else
content_tag_string(name, content_or_options_with_block, options, escape)
end
end
# File actionview/lib/action_view/helpers/capture_helper.rb, line 36
def capture(*args)
value = nil
buffer = with_output_buffer { value = yield(*args) }
if string = buffer.presence || value and string.is_a?(String)
ERB::Util.html_escape string
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question