0

导轨:3.0.11

Ruby:ruby 1.9.3dev(2011-09-23 修订版 33323)[i686-linux]

这是我的自定义布局文件:

custom_layout.html.haml

!!!
%html{ :xmlns => "http://www.w3.org/1999/xhtml", :"xml:lang" => "en", :lang => "en" }
  %head
    %meta{ :"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
    %title= SERVICE_NAME
    = render "shared/js_and_css"
  %body
    #wrapper.container_12
      #main.grid_12
        .grid_9.omega
          - flash.each do |name, message|
            = content_tag :p, message, :id => "flash_#{name}"
          = yield
        = yield :side_nav

    = render "layouts/footer"

查看文件:personal_information.html.erb

<div class="c1">
  <div class="c2">
    <div class="headings">
      <h1><%= t("general.edit_personal_information")%></h1>
    </div>
    <div class="info-area">
      <%= form_for @user, :html => { :multipart => true, :id => "user_form" }  do |f| %>
         <%= render :partial => "form", :object => f %>
      <% end %>
    </div>
  </div>
</div>

<% content_for :side_nav do %>
  <%= '<div class="grid_3 alpha">&nbsp;</div>'.html_safe  %>
<% end %>

生成的 HTML:

<body>
    <div class="container_12" id="wrapper">
        <div class="grid_12" id="main">
            <div class="grid_9 omega">
                <div class="c1">
                  <div class="c2">
                    <div class="headings">
                        <h1>Edit profile</h1>
                    </div>
                    <div class="info-area">
                        <form>
                            <!-- FORM ELEMENTS HERE -->
                        </form>
                      </div>
                 </div>
                </div>     
            </div>
        </div>
    </div>
    <div class="grid_3 alpha">&nbsp;</div>
</body>

使用content_for :side_nav设置的内容在div id="wrapper"之后呈现,而不是在div class="grid_9 omega"之后呈现。任何人都可以解释是什么导致了这种奇怪的行为,我该如何解决这个问题?

4

1 回答 1

0

您错过了=- 您只是在评估代码,但没有将其分配给视图。这应该解决它:

<%= content_for :side_nav do %>
  <%= '<div class="grid_3 alpha">&nbsp;</div>'.html_safe  %>
<% end %>

你可以摆脱插值:

<%= content_for :side_nav do %>
  <div class="grid_3 alpha">&nbsp;</div>
<% end %>
于 2012-08-17T13:42:10.380 回答