在开始之前,我想说我已经搜索并尝试了提供的多种解决方案。我仍然遇到同样的问题。
当我使用回形针上传图像时,它会显示损坏的图像。我右键单击并检查,发现我的页面正在提升和错误:获取http://localhost:3000/system/pins/images/000/000/008/medium/imgres.jpg 404(未找到)。
看法
<%= image_tag @pin.image.url %>
<p>
<strong>Description:</strong>
<%= @pin.description %>
</p>
<% if @pin.user == current_user %>
<%= link_to 'Edit', edit_pin_path(@pin) %>
<%= link_to 'Back', pins_path %>
<% end %>
模型
class Pin < ActiveRecord::Base
belongs_to :user
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end
控制器
class PinsController < ApplicationController
before_action :set_pin, only: [:show, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def index
@pins = Pin.all
end
def show
end
def new
@pin = current_user.pins.build
end
def edit
end
def create
@pin = current_user.pins.build(pin_params)
if @pin.save
redirect_to @pin, notice: 'Pin was successfully created.'
else
render :new
end
end
def update
if @pin.update(pin_params)
redirect_to @pin, notice: 'Pin was successfully updated.'
else
render :edit
end
end
def destroy
@pin.destroy
redirect_to pins_url
end
private
# Use callbacks to share common setup or constraints between actions.
def set_pin
@pin = Pin.find(params[:id])
end
def correct_user
@pin = current_user.pins.find_by(id: params[:id])
redirect_to pins_path, notice: "Not authorized to edit this pin" if @pin.nil?
end
# Never trust parameters from the scary internet, only allow the white list through.
def pin_params
params.require(:pin).permit(:description, :image)
end
end
宝石文件
source 'https://rubygems.org'
ruby '2.2.6'
gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'coffee-script-source', '1.8.0'
gem 'bootstrap-sass'
gem 'devise'
gem 'paperclip', '~> 4.2.0'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
我已经尝试降级和升级我的 gem 文件,添加一个可卡因 gem,将 :path => "" 和 :url => "" 添加到我的模型中,将时间戳设置为 false,重新启动我的计算机和服务器,卸载并重新安装imagemagick,手动下载 file.exe 并按照说明将代码调整到 development.rb 中,并更改我的图像的位置。我可能会忘记我尝试过的一些事情,因为我已经在谷歌上搜索并调整了几个小时。有没有人可以帮忙?