HAML - 为什么我的haml的文本都显示在顶线,尽管在代码的差异部分上呈现

时间:2012-04-20 15:53:30

标签: ruby-on-rails ruby haml

我有这个HAML页面:

-content_for :primary_content do

  Hmmm
  %strong{:class => "code", :id => "message"} Hello Alex!

  .container-fluid
    .row-fluid
      .span1 Hello 1
      .span4 Hello 4
      .span4 Hello 4 again
      .span3 Hello 3

  %strong{:class => "code"} End of page!

  .container-fluid
    .row-fluid
      .span9 My Disclosures o ye!
      .span3 This will be the side area

      // Ok....what is in home?
      // The two divs....

  -content_for :primary_content do
    -if signed_in?
      // =render "sidebar/common/primary_navigation"
      // If signed in, show the options for
      // 1) Logout | My Profile
      // 2) Create disclosure | show disclosures
      Signed in
    -else
      // =render "devise/sessions/form"
      NOT Signed in

出于某种原因,它会在顶行显示Not signed in Hmmm Hello Alex!,然后在其下方显示其他所有内容。

我很困惑,因为“未签名”位于页面底部,而“hmm Hello Alex”位于顶部。但出于某种原因,它在屏幕上呈现在一起。知道为什么吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

首先,我想指出您似乎有一个嵌套的content_for,这可能是一个问题。

其次,我建议将两个content_for块分开并专门为登录区域创建另一个。像

这样的东西
- content_for :login do
  -if signed_in?
    // =render "sidebar/common/primary_navigation"
    // If signed in, show the options for
    // 1) Logout | My Profile
    // 2) Create disclosure | show disclosures
    Signed in
  -else
    // =render "devise/sessions/form"
    NOT Signed in

然后把

yield :login

之后的某个地方
yield :primary_content

将问题分开并使其不会让任何内容踩到其他脚趾上。