ruby-on-railsrubyspreespree-auth-devise

The asset ' ' is not present in the asset pipeline


Screenshot of Error Message

If I do not add any image in product then it is working fine with Default Image,but if I add an image using admin panel of spree then on front-end I get this issue .

Inside :- app/helpers/spree/trackers_helper.rb

module Spree
  module TrackersHelper
    def product_for_segment(product, optional = {})
      {
        product_id: product.id,
        sku: product.sku,
        category: product.category.try(:name),
        name: product.name,
        brand: product.brand.try(:name),
        price: product.price,
        currency: product.currency,
        url: product_url(product),
      }.tap do |hash|
        hash[:image_url] = asset_url(optional.delete(:image).attachment) if optional[:image]
      end.merge(optional).to_json.html_safe
    end
  end
end

Inside :- app/views/spree/shared/_products.html.erb

<% content_for :head do %>
  <% if products.respond_to?(:total_pages) %>
    <%= rel_next_prev_link_tags products %>
  <% end %>
<% end %>

<div data-hook="products_search_results_heading">
  <% if products.empty? %>
    <div data-hook="products_search_results_heading_no_results_found">
      <%= Spree.t(:no_products_found) %>
    </div>
  <% elsif params.key?(:keywords) %>
    <div data-hook="products_search_results_heading_results_found">
      <h6 class="search-results-title"><%= Spree.t(:search_results, keywords: h(params[:keywords])) %></h6>
    </div>
  <% end %>
</div>

<% if products.any? %>
  <div id="products" class="row" data-hook>
    <%= render partial: 'spree/products/product', collection: products, locals: { taxon: @taxon } %>
  </div>
<% end %>

<% if products.respond_to?(:total_pages) %>
  <%= paginate products, theme: 'twitter-bootstrap-3' %>
<% end %>

Solution

  • Spree is using the ActiveStorage to store the image file. They are in the storage folder of the spree project. One way to upload them in a batch manner is to use the rest API

    https://guides.spreecommerce.org/api/product_images.html

    For the rest-api, I have been using unirest.

    POST /api/v1/products/a-product/images
    

    a-product = friendly_id (slug name to be exact), they are stored in friendly_id_slug tables. When you upload an image to Spree, Spree will look up the slug name in that table and upload it to the ActiveStorage. The records will be saved in spree_assets, active_storage_blobs and active_storage_attachments table respectively.