ruby-on-rails 为什么在使用Ruby on Rails时,我的徽标不显示在 Bootstrap 导航栏中?

mefy6pfw  于 2023-06-07  发布在  Ruby
关注(0)|答案(1)|浏览(132)

我正在使用Ruby on Rails,我试图将logo.png图像放在引导导航栏中。所以我在app/views/home/_header.html.erb中使用了这段代码

<nav class="navbar navbar-expand-lg bg-primary " data-bs-theme="dark"> 
  <div class="container-fluid">
   <!-- <a class="navbar-brand" href="#">Estrutecnia</a> -->
 <a class="navbar-brand" href="#">
      <img src="logo.png" alt="Estrutecnia" width="30" height="24">
    </a>

    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
          <ul class="dropdown-menu">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
      <form class="d-flex" role="search">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>

</nav>

问题是徽标没有出现,请查看导航栏x1c 0d1x
并显示下一个错误

Started GET "/logo.png" for 127.0.0.1 at 2023-06-02 20:05:47 -0500

ActionController::RoutingError (No route matches [GET] "/logo.png"):

我试着把logo.png文件放在根目录下,我猜这是Gemfile和www.example.com文件所在的文件夹README.md。我希望logo.png出现在导航栏上,但导航栏的左侧会出现一个坏掉的文件图标,如上图所示。

envsm3lx

envsm3lx1#

图像通常放置在app/assets/images目录中。
当你使用ActionView image_tag助手渲染一个视图时,Rails会自动为你填充图像源:

image_tag('logo.png')
# => <img src='/assets/icon.png>

这是在Rails中处理图像的惯用方法,但是当然,没有什么可以阻止您在标记中包含<image src='/assets/icon.png'>

相关问题