Paperclip ActionController :: RoutingError:没有路由匹配[GET]

时间:2017-05-09 00:17:06

标签: ruby-on-rails ruby rspec paperclip spree

我正在尝试进行一些Capybara / Poltergeist RSPEC集成测试。

在我的测试中,我正在创建一个图像并使用Paperclip“上传”它。

型号:Platform::ContentImage

  has_attached_file :attachment, {
    styles: lambda { |a| a.instance.styles_by_image_type},
    processors:  [:thumbnail, :paperclip_optimizer],
    paperclip_optimizer: {
      nice: 19,
      jpegoptim: { allow_lossy: true, strip: :all, max_quality: 75 },
      jpegrecompress: {allow_lossy: true, quality: 3},
      jpegtran: {progressive: true},
      optipng: { level: 2 },
      pngout: false
    },
    path: "#{'public/' if Rails.env.test?}content_image/:id/:style/:basename.:extension",
    convert_options: { :all => '-auto-orient +profile "exif"' },
    s3_headers: { 'Cache-Control' => 'max-age=31536000'}
  }

在我的application.rb测试环境中

config.paperclip_defaults = {
        url: "/public/:class/:id/:style/:basename.:extension"
      }

我的错误已退回

ActionController::RoutingError:
       No route matches [GET] "/system/platform/content_images/attachments/000/000/001/thumb/blue_night_swatch.jpg"

我正在尝试显示图像,但我似乎无法正确配置URL。由于我覆盖了Platform::ContentImage模型中的默认值,因此它成功创建了目录public/content_image,但是在测试期间,我似乎无法'解密'类名。我可以在Platform::ContentImage定义中指定URL,但仅限于测试环境吗?

1 个答案:

答案 0 :(得分:-1)

将此消息放在表单上,​​看看它没有保存的原因:

<% if @portifolio.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@portifolio.errors.count, "error") %>
prohibited this portifolio from being saved:</h2>
<ul>
<% @portifolio.errors.full_messages.each do |message| %>
  <li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>