我正在使用 paperclip gem 来上传图片,但这些图片并未存储在公共文件夹中或任何地方,而是显示missing.png。我已经指定了url,path。
模型 - 这是使用回形针配置的模型
class AudiModel < ActiveRecord::Base
has_attached_file :exterior_image,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename",
:styles => { :medium => "300x300>", :thumb => "100x100>" }
validates_attachment_content_type :exterior_image, content_type: /\Aimage\/.*\Z/
end
位指示
class AudiModelsController < ApplicationController
before_action :set_audi_model, only: [:show, :edit, :update, :destroy]
# GET /audi_models
# GET /audi_models.json
def index
@audi_models = AudiModel.all
end
# GET /audi_models/1
# GET /audi_models/1.json
def show
end
# GET /audi_models/new
def new
@audi_model = AudiModel.new
end
# GET /audi_models/1/edit
def edit
end
# POST /audi_models
# POST /audi_models.json
def create
@audi_model = AudiModel.new(audi_model_params)
respond_to do |format|
if @audi_model.save
format.html { redirect_to @audi_model, notice: 'Audi model was successfully created.' }
format.json { render :show, status: :created, location: @audi_model }
else
format.html { render :new }
format.json { render json: @audi_model.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /audi_models/1
# PATCH/PUT /audi_models/1.json
def update
respond_to do |format|
if @audi_model.update(audi_model_params)
format.html { redirect_to @audi_model, notice: 'Audi model was successfully updated.' }
format.json { render :show, status: :ok, location: @audi_model }
else
format.html { render :edit }
format.json { render json: @audi_model.errors, status: :unprocessable_entity }
end
end
end
# DELETE /audi_models/1
# DELETE /audi_models/1.json
def destroy
@audi_model.destroy
respond_to do |format|
format.html { redirect_to audi_models_url, notice: 'Audi model was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_audi_model
@audi_model = AudiModel.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def audi_model_params
params.require(:audi_model).permit(:car_model, :variant, :introduction, :engine, :exterior_image, :video, :brochure)
end
end
答案 0 :(得分:0)
解决了!路径应该是这样的。需要在路径中指定attributte名称。
:path =&gt; &#34;:RAILS_ROOT /公共/系统/ exterior_image /:附接/:id_partition /:风格/:文件名&#34;