Ruby 使用回形针在rails 4上上载图像显示损坏的图像
在我开始之前,我想说的是,我已经在谷歌上搜索并尝试了提供的多种解决方案。我仍然遇到同样的问题 当我使用回形针上传图像时,它会显示一个损坏的图像。我右键单击并检查,发现我的页面正在提升,错误:Get 404(未找到) 看法Ruby 使用回形针在rails 4上上载图像显示损坏的图像,ruby,ruby-on-rails-4,imagemagick,paperclip,brokenimage,Ruby,Ruby On Rails 4,Imagemagick,Paperclip,Brokenimage,在我开始之前,我想说的是,我已经在谷歌上搜索并尝试了提供的多种解决方案。我仍然遇到同样的问题 当我使用回形针上传图像时,它会显示一个损坏的图像。我右键单击并检查,发现我的页面正在提升,错误:Get 404(未找到) 看法 我已尝试降级和升级我的gem文件,添加一个gem,将:path=>“”和:url=>“”添加到我的模型,将时间戳设置为false,重新启动我的计算机和服务器,卸载并重新安装imagemagick,手动下载file.exe,并按照说明将代码调整为in development.rb
我已尝试降级和升级我的gem文件,添加一个gem,将:path=>“”和:url=>“”添加到我的模型,将时间戳设置为false,重新启动我的计算机和服务器,卸载并重新安装imagemagick,手动下载file.exe,并按照说明将代码调整为in development.rb,以及更改我的图像的位置。我可能忘记了我尝试过的一些事情,因为我已经在谷歌上搜索了好几个小时,并且已经适应了。有人可以帮忙吗?高级曲别针会将上传的文件写入本地文件,并将文件信息存储在数据库中以供查找。rails返回404的事实表明1)文件没有被写入,或者2)rails没有正确地为文件提供服务 关于存储的回形针文档可作为参考: 默认情况下,rails应该为公共目录中的文件提供服务,而默认情况下,曲别针将文件存储在
public/system
下,因此一般来说,文件服务应该在开发环境中自动工作
您能验证文件
public/system/pins/images/000/000/008/medium/imgres.jpg
是否存在吗?谢谢您的回答!有没有命令我可以通过gitbush来检查?当我在sublime文本上查看文件时,它确实存在。此外,该文件位于original/imgres.jpg下。我从erb中删除了:medium参数。
<%= 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