Search code examples
ruby-on-railsrubydeviseimagesource

Ruby on Rails not loading images in Devise


I have strange error with images (never encountered it before).

This is screenshot of the main page - <%= render 'layouts/header %>

enter image description here

Nothing wrong there...

Now - I have put same code (<%= render 'layouts/header %>) into devise/sessions/new.html.erb and it does not read logos anymore.

enter image description here

(same happens with footer)

-> How to fix this? -> How to prevent it in future?

I thought that rails will always load images the same way it does every time.

header.html.erb

  <header id="home">
<div class="main-nav">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".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="index.html">
        <h1><img class="img-responsive" src="assets/logo.png" alt="logo"></h1>
      </a>                    
    </div>
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav navbar-right">                 
        <li class="scroll active"><a href="#">Home</a></li>     
      </ul>
    </div>
  </div>
</div><!--/#main-nav-->


Solution

  • Fixed

    Problem was that I should have used image_tag instead of standard html img src.

    So:

    This:

    <img class="img-responsive" src="assets/logo.png" alt="logo">
    

    Should be changed to this:

    <%= image_tag("logo.png") %>