2013-10-31 111 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: ""

他們都與本地人一起工作,並尋找一個預先強調的文件。