如何在渲染部分缩小后继续编写嵌套代码?

时间:2014-03-17 19:56:02

标签: ruby-on-rails slim-lang

例如,我想做这样的事情:

= render 'header_splash'
  #about.section
    h2 You've reached our home page.

... header_splash.slim看起来像这样:

#header_splash
  h1 Here's the splash image and the nav elements

我希望#about部分在header_splash div内呈现,但它在其外部呈现,即使它嵌套在代码中。

是否可以像这样嵌套?

1 个答案:

答案 0 :(得分:1)

你做不到。如果你想要在局部渲染的东西,你需要在局部渲染它​​。如有必要,您可以传入其他变量:

= render partial: 'header_splash', locals: { header_text: "you've reached ..." }

locals哈希将在您的部分变量中可用:

h2= header_text