Ruby on rails 回形针上载并显示图像不工作

Ruby on rails 回形针上载并显示图像不工作,ruby-on-rails,ruby,imagemagick,paperclip,Ruby On Rails,Ruby,Imagemagick,Paperclip,我在运行Ruby 2.3.3和Rails 5.1.4的Windows7上安装了曲别针->5.1和最新的ImageMagick(是的,我知道) 我按照回形针说明的建议安装了file.exe,并在路径中添加了“C:\Program Files(x86)\GnuWin32\bin” 当我上传我的图片时,出现以下错误: ActionController::RoutingError (No route matches [GET] "/images/medium/missing.png"): Action

我在运行Ruby 2.3.3和Rails 5.1.4的Windows7上安装了曲别针->5.1和最新的ImageMagick(是的,我知道)

我按照回形针说明的建议安装了file.exe,并在路径中添加了“C:\Program Files(x86)\GnuWin32\bin”

当我上传我的图片时,出现以下错误:

ActionController::RoutingError (No route matches [GET] "/images/medium/missing.png"):
ActionController::RoutingError (No route matches [GET] "/system/recipes/images/000/000/005/medium/Capture777.PNG"):
当我试图查看show页面以查看图像时,会出现以下错误:

ActionController::RoutingError (No route matches [GET] "/images/medium/missing.png"):
ActionController::RoutingError (No route matches [GET] "/system/recipes/images/000/000/005/medium/Capture777.PNG"):
你能告诉我如何正确上传我的图片并展示它吗?我假设这些错误会提供一些输入。我试着去看其他的SO文章,但到目前为止没有任何帮助


这是我的路线



这是我的控制器显示/新操作和查找配方参数



这是我的模型



这是我的_form.html.haml



问题在于您尝试使用样式选项的方式,它必须是
样式
,请将其替换,然后重试:

class Recipe < ApplicationRecord
  has_attached_file :image, styles: { medium: '400x400#' }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end
类配方
这使得曲别针仅执行以下命令:

  • Command::file-b--mime
    启动事务
  • Command::file-b--mime
    创建副本
相反:

  • Command::file-b--mime
  • 命令::标识-格式
  • 命令::标识-格式%m
  • Command::convert
  • Command::file-b--mime
因此,您无法通过
:medium
样式获取图像,但您可以访问其url并通过图像标记显示,但样式不起作用

= image_tag @recipe.image.url(:medium, class: "recipe_image")
%h1= @recipe.title
%p= @recipe.description
= link_to 'Back', root_path, class: 'btn btn-info'
= link_to 'Edit', edit_recipe_path, class: 'btn btn-primary'
= link_to 'Delete',recipe_path, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
= simple_form_for @recipe, html: { multipart: true } do |f|
- if @recipe.errors.any?
#errors
  %p
    = @recipe.errors.count
    Prevented this recipe from saving
  %ul
    - @recipe.errors.full_messages.each do |msg|
      %li = msg
.panel-body
= f.input :title, input_html: { class: 'form-control' }
= f.input :description, input_html: { class: 'form-control' }
= f.file_field :image, input_html: { class: 'form-control' }


= f.button :submit, class: 'btn btn-primary'
class Recipe < ApplicationRecord
  has_attached_file :image, styles: { medium: '400x400#' }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end