首页 > 解决方案 > CSS applied to all pages but one - Ruby/Sinatra

问题描述

I'm creating a simple web application with Ruby using Sinatra, and when modifying the views, the CSS is applied to all .erb files except one. I'm not quite sure what the issue is. I've tried:

This is my layout.erb file

<br/>
<h2>Upload a Video</h2>
<br/>
<br/>
<form action="/create_video" method="POST">
  <div class="col-6">
    <label for="videoTitle">Video Title</label>
    <input type="text" class="form-control" aria-describedby="emailHelp" placeholder="Enter video title" name="title">
  </div>
  <br/>
  <div class="col-6">
    <label for="videoDescription">Video Description</label>
    <input type="text" class="form-control" placeholder="Enter video description" name="description">
  </div>
  <br/>
    <br/>
    <div class="col-6">
     <label for="videoURL">Video Link</label>
     <input type="text" class="form-control" placeholder="Enter link to video" name="l_url">
    </div>
    <br/>
    <div class="col-6">
     <label for="listingUrl">Company</label>
     <input type="text" class="form-control" placeholder="Enter company name" name="company">
    </div>
    <br/>
  &nbsp;&nbsp;<button type="submit" class="btn btn-primary">Submit</button>
</form>
<br/>
<br/>
</div>

My layout.erb file

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Roboto:300|Niramit|Nunito" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" type="text/css" href="animate.css">
</head>
<body>

    <%= erb :navigation %>

    <main role="main">

        <%= yield %>

    </main>


    <footer class="end">
         <div class="footer-grid">
      <div class="footer-one">
        <p> logo<p>
      </div>
        <div class="footer-two">
            <p>&copy; Copyright Ignite 2018. All rights reserved.</p>
            <p>Terms of use • Press Inquiries • General Inquiries • Investors</p>
        </div>
        <div class="footer-three">
        <img src="https://image.flaticon.com/icons/svg/185/185981.svg" width=40 height=40>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <img src="https://image.flaticon.com/icons/svg/185/185961.svg" width=40 height=40>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <img src="https://image.flaticon.com/icons/svg/185/185985.svg" width=40 height=40>
        </div>
    </footer>


    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

Finally, this is a small snippet where the style sheet IS working:

   <br/>
   <br/>
   <h2>Videos</h2>
   <br/>
   <br/>
   <% @videos.each do |v| %>
      <img src="<%= v.logo %>" width="110" height="110">
      <h3><%= v.title %></h3>
      <p><%= v.l_url %></p>
      <p><%= v.description %> </p>
   <br/>
   <% end %>
   <br/>
   <br/>
   <br/>
   <br/>
</div>

Any idea what might be wrong? I appreciate any tips.

标签: cssruby-on-railsrubysinatra

解决方案


我认为这可能会解决您的问题,我认为您的样式表的链接可能已损坏。如果页面不在顶部路径中,如果它看起来像这样:

http://localhost/namespace/ThisIsThePage

在您的layout.erb-file 中,您使用以下方式引用样式表:

href="style.css"

在您的 CSS-imports 中,我建议您使用例如参考样式表:

href="/style.css"

注意文件名前的斜杠。斜杠告诉浏览器该资源将从您的网络服务器的根路径加载。如果没有斜线,浏览器将尝试style.css从下面的路径中获取:

http://localhost/namespace/style.css


推荐阅读