为什么在link_to显示时image_tag不显示图像?

时间:2019-03-19 10:49:04

标签: ruby-on-rails ruby

我想通过回形针gem在购物车中显示图片,但与link_一起使用时,它不能与image_tag一起使用

这有效:

<% simple_current_order.line_items.all.each do |line_item| %>
  <%= link_to mini_image(line_item.variant)), product_path(line_item) %> 
<% end %>

这不是

    <% simple_current_order.line_items.all.each do |line_item| %>
      <%= image_tag mini_image(line_item.variant) %> 
    <% end %>

image.rb模型

module Spree
  class Image < Asset
    validate :no_attachment_errors

    has_attached_file :attachment,
                      styles: { mini: '48x48>', small: '100x100>', product: '240x240>', large: '600x600>' },
                      default_style: :product,
                      url: '/spree/products/:id/:style/:basename.:extension',
                      path: ':rails_root/public/spree/products/:id/:style/:basename.:extension',
                      convert_options: { all: '-strip -auto-orient -colorspace sRGB' }
    validates_attachment :attachment,
                         :presence => true,
                         :content_type => { :content_type => %w(image/jpeg image/jpg image/png image/gif) }

    # save the w,h of the original image (from which others can be calculated)
    # we need to look at the write-queue for images which have not been saved yet
    after_post_process :find_dimensions

    #used by admin products autocomplete
    def mini_url
      attachment.url(:mini, false)
    end

    def find_dimensions
      temporary = attachment.queued_for_write[:original]
      filename = temporary.path unless temporary.nil?
      filename = attachment.path if filename.blank?
      geometry = Paperclip::Geometry.from_file(filename)
      self.attachment_width  = geometry.width
      self.attachment_height = geometry.height
    end

    # if there are errors from the plugin, then add a more meaningful message
    def no_attachment_errors
      unless attachment.errors.empty?
        # uncomment this to get rid of the less-than-useful interim messages
        # errors.clear
        errors.add :attachment, "Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
        false
      end
    end
  end
end

找不到带有图像标签的图像,有人知道为什么吗?

0 个答案:

没有答案