Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprockets::Rails::Helper::AssetNotFound - The asset "my_logo.jpeg" is not present in the asset pipeline

Tags:

Receiving this error, what am I missing?

Sprockets::Rails::Helper::AssetNotFound in Static#index:

The asset "my_logo.jpg" is not present in the asset pipeline.

ActionView::Template::Error (The asset "my_logo.jpg" is not present in the asset pipeline.):
    1: <%= image_tag "my_logo.jpg" %>
  1. I make a new Ruby on Rails application rails new my_app # Rails 6.0.3.2

  2. Allow it to install the gems, web packer, etc..

  3. Add config.assets.compile = false to config/environments/development.rb

  4. Add a static controller and index file with this content

    app/controllers/static_controller.rb

    class StaticController < ApplicationController
      def index
        render :index, layout: false
      end
    end
    

    app/views/static/index.html.erb

    <%= image_tag "my_logo.jpg" %>
    
  5. Add the my_logo.jpeg file to app/assets/images/

    wget https://jpeg.org/images/jpeg2000-home.jpg -O app/assets/images/my_logo.jpg
    
  6. Precompile the assets: bundle exec rake assets:precompile

  7. Run rails server as: bundle exec rails server

I can see the file is in public/assets/ as this name: my_logo-484af9fb82bc8a0279ef38b527402b5697475bd8f827251f46fbb182be6c07a1.jpg

It will show the image just fine if I set this to true: config.assets.compile = true

Also the manifest file content from public/assets/.sprockets-manifest-a7f9f10978778e828273bf0c790645f6.json

{
  "files": {
    "manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js": {
      "logical_path": "manifest.js",
      "mtime": "2020-06-28T03:59:01+00:00",
      "size": 2,
      "digest": "75a11da44c802486bc6f65640aa48a730f0f684c5c07a42ba3cd1735eb3fb070",
      "integrity": "sha256-daEdpEyAJIa8b2VkCqSKcw8PaExcB6Qro80XNes/sHA="
    },
    "application-b324c44f04a0d0da658824105489a2676d49df561c3d06723770321fd441977c.css": {
      "logical_path": "application.css",
      "mtime": "2020-06-28T03:59:01+00:00",
      "size": 675,
      "digest": "4998ce12ecefa6ba42de36e4beac458527529608f8cf0fe6c97acd87850045e4",
      "integrity": "sha256-SZjOEuzvprpC3jbkvqxFhSdSlgj4zw/myXrNh4UAReQ="
    },
    "my_logo-484af9fb82bc8a0279ef38b527402b5697475bd8f827251f46fbb182be6c07a1.jpg": {
      "logical_path": "my_logo.jpg",
      "mtime": "2020-06-28T03:59:01+00:00",
      "size": 20974,
      "digest": "acda9fe5166e93aef6ef9572c07e9a6bf3f4879180765b3d95d9a631b852191c",
      "integrity": "sha256-rNqf5RZuk67275VywH6aa/P0h5GAdls9ldmmMbhSGRw="
    }
  },
  "assets": {
    "manifest.js": "manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js",
    "application.css": "application-b324c44f04a0d0da658824105489a2676d49df561c3d06723770321fd441977c.css",
    "my_logo.jpg": "my_logo-484af9fb82bc8a0279ef38b527402b5697475bd8f827251f46fbb182be6c07a1.jpg"
  }
}

Also I turned on config.assets.unknown_asset_fallback = true to see what the path is, it comes out to being: http://localhost:3000/images/my_logo.jpg and when it's false (when it works), I get this path: http://localhost:3000/assets/my_logo-484af9fb82bc8a0279ef38b527402b5697475bd8f827251f46fbb182be6c07a1.jpg

like image 320
nictrix Avatar asked Jun 28 '20 00:06

nictrix


1 Answers

The file in public/assets ends in .jpg. You're using .jpeg in your image_tag.

You need to rename your source image to end in .jpg, and update your image_tag invocation:

<%= image_tag('my_logo.jpg') %>
like image 161
meagar Avatar answered Sep 30 '22 19:09

meagar