Rails布局样式表在渲染时消失

时间:2015-05-28 03:37:03

标签: css ruby-on-rails

所以我刚开始一个新项目并决定使用rails来构建框架。但是在渲染时我的布局剥离样式表遇到了一个小问题:

application.html.erb:

<!doctype html>
<html>
  <head>
    <title><%= yield(:title) %></title>
    <% stylesheet_link_tag "bootstrap.min", media: "all", "data-turbolinks-track" => true %>
    <% stylesheet_link_tag "styles", media: "all", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
  </head>
  <body>
    <div class="container-fluid"> <!-- Start Container -->
      <nav class="navbar navbar-inverse navbar-fixed-top"></nav>
    </div>

    <div class="container-fluid add_margin">
      <div class="page-header">
        <h1>XQA <small>Revolutionizing Customer Service</small></h1>
      </div>

    </div> <!-- End Container -->

    <%= yield %>

    <!-- JS After this line -->
    <% javascript_include_tag "jquery-2.1.4" %>
    <% javascript_include_tag "bootstrap.min" %>
  </body>
</html>

服务器输出:

~/Projects/QA$ rails server
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-05-27 22:30:26] INFO  WEBrick 1.3.1
[2015-05-27 22:30:26] INFO  ruby 2.1.2 (2014-05-08) [x86_64-linux-gnu]
[2015-05-27 22:30:26] INFO  WEBrick::HTTPServer#start: pid=13087 port=3000


Started GET "/" for 127.0.0.1 at 2015-05-27 22:32:25 -0500
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by HomeController#index as HTML
  Rendered home/index.erb within layouts/application (0.8ms)
Completed 200 OK in 159ms (Views: 151.9ms | ActiveRecord: 0.0ms)

请指出我正确的方向或登录我如何进一步解决这个问题。谢谢大家!

生成的HTML源:

<!doctype html>
<html>
  <head>
    <title>yeah</title>
    <meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="0kNM9OV6jBvQdFiUBA1PqDiIlJbkUyK0eLEllIKlguMc3+C9oq2rxiObTlH/liDmcpDENF3QEf3hYMWEqjJZ6w==" />
  </head>
  <body>
    <div class="container-fluid"> <!-- Start Container -->
      <nav class="navbar navbar-inverse navbar-fixed-top"></nav>
    </div>

    <div class="container-fluid add_margin">
      <div class="page-header">
        <h1>XQA <small>Revolutionizing Customer Service</small></h1>
      </div>

    </div> <!-- End Container -->



    <!-- JS After this line -->
  </body>
</html>

1 个答案:

答案 0 :(得分:3)

您未输出stylesheet_link_tag声明 - 您需要使用<%=<%将评估代码但不输出代码 - <%=将对其进行评估并输出。

例如。 <%= stylesheet_link_tag ...