2013-10-31 82 views
7

我创建了一个haml-partial,我想用它作为默认头。在渲染时,我可以选择给它一个块来替换部分默认内容。Rails 4,使用haml内的可选块渲染部分/布局

我已经试过许多东西:

render partial: "partial", capture: do 
# Don't really know why I tried this, Syntax error ofcourse. 

render partial: "partial" do 
# 'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path. 

render layout: "partial" do 
# Works, but: 

render layout: "partial" 
# You invoked render but did not give any of :partial, :template, :inline, :file or :text option. 
# So, it always needs the block 

我不知道任何其他的选择吗?

回答

13

当你需要一个块时使用render layout: ""

当您不使用块时使用render partial: ""

他们都与本地人一起工作,并寻找一个预先强调的文件。