资产“”不在资产管道中

时间:2018-07-17 06:27:56

标签: ruby-on-rails ruby spree spree-auth-devise spree-upgrade

Screenshot of Error Message

如果我没有在产品中添加任何图像,则它可以与默认图像配合使用,但是如果我使用spree的管理面板添加图像,则在前端会出现此问题。 < / p>

内部:-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

内部:-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 %>

1 个答案:

答案 0 :(得分:0)

Spree正在使用ActiveStorage存储映像文件。它们位于spree项目的存储文件夹中。批量上传它们的一种方法是使用其余的API

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

对于rest-api,我一直在使用unirest。

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

a产品 = friendly_id(准确的名称),它们存储在friendly_id_slug表中。当您将映像上传到Spree时,Spree将在该表中查找该段名称,并将其上传到ActiveStorage。记录将分别保存在spree_assets,active_storage_blobs和active_storage_attachments表中。