检测引导程序导航栏链接失败

时间:2014-05-24 10:20:34

标签: twitter-bootstrap ruby-on-rails-4 twitter-bootstrap-3 slim-lang

在我的rails应用程序中,使用bootstrap3设置样式,我决定切换Slim而不是现有的ERB。当我将erb视图文件转换为slim时,我注意到导航栏链接的样式已经消失。

# app/views/layouts/_navbar.html.slim
nav.navbar.navbar-default
  .container
    .navbar-header.navbar-left
      button(type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-navbar-collapse")
        span.sr-only Toggle navigation
        span.icon-bar
        span.icon-bar
        span.icon-bar
      a.navbar-brand href="/" Foody

    .collapse.navbar-collapse.navbar-right#bs-navbar-collapse
      ul.nav.navbar-nav
      - if user_signed_in?
          li = link_to current_user.email, edit_user_registration_path
          li = link_to 'New Recipe', new_recipe_path
          li = link_to 'Sign Out', destroy_user_session_path, method: :delete, confirm: "Are you sure?"
      - else
          li = link_to 'Sign In', new_user_session_path
          li = link_to 'Sign Up', new_user_registration_path

      span.clearfix

以下是我转换自的原始文件:

# app/views/layouts/_navbar.html.erb
<nav class="navbar navbar-default" role="navigation">
  <div class="container">
    <div class="navbar-header navbar-left">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="/">Foody</a>
    </div>
    <div class="collapse navbar-collapse navbar-right" id="bs-navbar-collapse">
      <ul class="nav navbar-nav">
        <% if user_signed_in? %>
            <li><%= link_to current_user.email, edit_user_registration_path %></li>
      <li><%= link_to 'New Recipe', new_recipe_path %></li>
            <li><%= link_to 'Sign Out', destroy_user_session_path, method: :delete, confirm: "Are you sure?" %></li>
        <% else %>
            <li><%= link_to 'Sign In', new_user_session_path %></li>
            <li><%= link_to 'Sign Up', new_user_registration_path %></li>
        <% end %>
      </ul>
    </div>
    <span class="clearfix"></span>
  </div>
</nav>

这是正常和结果的结果。响应模式

enter image description here

这是输出(抱歉复杂)

<div class="collapse navbar-collapse navbar-right" id="bs-navbar-collapse">
<ul class="nav navbar-nav"></ul><li><a href="/users/sign_in">Sign In</a></li>
<li><a href="/users/sign_up">Sign Up</a></li><span class="clearfix"></span>

我哪里做错了?

1 个答案:

答案 0 :(得分:1)

ul.nav.navbar-nav导致问题后的缩进失败行为。需要更多练习Slim。特别感谢Graeme!

nav.navbar.navbar-default
  div.container
    div.navbar-header.navbar-left
      button(type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-navbar-collapse")
        span.sr-only Toggle navigation
        span.icon-bar
        span.icon-bar
        span.icon-bar
      a.navbar-brand href="/" Foody
    div.collapse.navbar-collapse.navbar-right#bs-navbar-collapse
      ul.nav.navbar-nav
        - if user_signed_in?
          li = link_to current_user.email, edit_user_registration_path
          li = link_to 'New Recipe', new_recipe_path
          li = link_to 'Sign Out', destroy_user_session_path, method: :delete, confirm: "Are you sure?"
        - else
          li = link_to 'Sign In', new_user_session_path
          li = link_to 'Sign Up', new_user_registration_path
    span.clearfix