I want to be able to display the images in the partial template outside of the top page.

Asked 2 years ago, Updated 2 years ago, 376 views

You want to be able to display the images in the header no matter which page you transition to.

Creating web applications in Ruby.
After creating _header.html.erb using a partial template, the image does not appear when you leave the top page.
There are no errors on the browser.

Example.ActionController:: RoutingError (No route matches [GET]"/css/style.css"):

A similar error is observed on the terminal for a few minutes.

Each view invokes a partial template with <%=render "shared/header"%>.

I look forward to your kind cooperation.

Source Codes Affected

_header.html.erb

<!doctype html>
<html lang="ja">
<head>
<metacharset="UTF-8">
<div class="title">
<%if user_signed_in?%>
  <h2><%=link_to current_user.nickname%>/h2>
  <%=link_to "logout", destroy_user_session_path, method::delete%>
<%else%>
  <h2>/h2>
  <%=link_to "New Registration", new_user_registration_path%>
  <%=link_to "login", new_user_session_path%>
<%end%>
</div>


<meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Today's Training</title>
<link rel="stylesheet" media="all" href="css/less.min.css"/>
<link rel="stylesheet" media="all" href="css/style.css"/>
<script src="js/jquery-2.1.4.min.js">/script>
<script src="js/style.js"></script>

<!--Favicon-->
<link rel="icon" type="assets/png" href="assets/favicon.png">

</head>
<body>
<header>    
<div class="container">
<div class="row">
    <div class="colspan-12">
    <div class="head">
        <h1><%=link_to "training diary", root_path%>/h1>
        <div class="snsbox">
            <img src="assets/in-icon.png" alt="Instagram">
            <img src="assets/fb-icon.png" alt="Facebook">/div>
        </div>
    </div></div>

<div class="row">
    <div class="colspan-12">
        <nav>
            <divid="open"></div>
            <divid="close"></div>   
            <divid="navi">
        <ul>
            <li><%=link_to "home", root_path%>/li>
            <li><%=link_to "Today's Training", new_main_path%>/li>


            </ul>
                </div>
        </nav>
    </div>
        </div>
    </div>

ruby html

2022-09-30 21:59

1 Answers

Since the src of img specifies a relative path, the top page and the child hierarchy page will change their destination

for the following example:
<img src="assets/in-icon.png" alt="Instagram">

For http://example.com,
Visit =>http://example.com/assets/in-icon.png

For http://example.com/mains,
Visit =>http://example.com/mains/assets/in-icon.png

will change the destination

Make sure to start with a slash as an absolute path.Access from the top path

<img src="/assets/in-icon.png" alt="Instagram">
<img src="/assets/fb-icon.png" alt="Facebook">


2022-09-30 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.