【发布时间】:2012-10-26 17:12:48
【问题描述】:
我发现你可以通过查看 Rails 源代码来刷新content_for。 https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/capture_helper.rb
Rails 来源:
def content_for(name, content = nil, options = {}, &block)
if content || block_given?
if block_given?
options = content if content
content = capture(&block)
end
if content
options[:flush] ? @view_flow.set(name, content) : @view_flow.append(name, content)
end
nil
else
@view_flow.get(name)
end
end
我正在尝试设置options[:flush] = true,但遇到了一些问题。 options[:flush] 在我下面的代码中没有评估为真。
我的代码:
content_for(affiliate_link_pos.to_sym, {:flush=>true}) do
render page
end
编辑:
我也尝试过传递第三个参数(内容),但我得到了wrong number of argument error (3 for 2)。
content_for(affiliate_link_pos.to_sym, "true", {:flush=>true}) do
【问题讨论】:
-
刚刚弄清楚原因。我在 Rails 3.2.6 上,content_for 源是 3.2.8。
标签: ruby-on-rails ruby-on-rails-3