这个问题我一直试图在网站堆栈的帮助下解决。但不幸的是我不能这样做。所以我决定伸出援助之手。
我已尝试过所有这些链接来解决此问题。但它们都不起作用。
http://stackoverflow.com/questions/25934465/rails-paperclip-not-showing-image
http://stackoverflow.com/questions/9170335/paperclip-images-not-displaying-in-rails-app
http://stackoverflow.com/questions/23971226/rails-image-not-showing-up-with-paperclip
http://stackoverflow.com/questions/31348628/paperclip-not-showing-image-even-though-url-images-in-correct-places
http://stackoverflow.com/questions/7425001/specifying-missing-png-in-paperclip
http://stackoverflow.com/questions/25249252/paperclip-where-to-place-the-
missing-png-default-image
http://stackoverflow.com/questions/38734116/ruby-paperclip-how-to-get-missing-png-to-work
现在我的问题是,它始终显示一个丢失的方形图像。
以下是我的代码
Recipe.rb
class Recipe < ApplicationRecord
has_attached_file :image, styles: { medium: "400x400#" },
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename"
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
end
Recipe的show.html.haml
= image_tag @recipe.image.url(:medium, class: "recipe_image")
Recipe的new.html.haml
= simple_form_for @recipe, html: { multipart: true } do |f|
- if @recipe.errors.any?
#errors
%p
= @recipe.errors.count
Prevented this recipe froms 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.input :image, input_html: { class: 'form-control' }
= f.button :submit, class: "btn btn-primary"
答案 0 :(得分:-1)
暂时遇到同样的问题,但我现在就修好了。
我做了什么:浏览您的站点文件夹以查看图像的保存位置。即我的保存在与post.rb文件中显示的路径不同的路径中。 我可以建议解决它。右键单击并检查损坏图像上的元素并进行比较
我相应调整,现在工作正常:)