2016-03-22 39 views
0

我正在使用回形針寶石上傳圖片,但這些圖片沒有存儲在公共文件夾或任何地方,而是它顯示missing.png。我已經指定了url,路徑。回形針圖片不存儲在任何地方(missing.png)rails

模式 - 這是用回形針

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

你能告訴相關的控制器代碼和你使用的是什麼版本的軌道? – dp7

+0

rails版本是4.2.5以上是我的控制器代碼。我使用scaffold命令生成它。 – Ekta

回答

0

配置的模型解決它!路徑應該是這樣的。還需要在路徑中指定attributte名稱。

:路徑=> 「:RAILS_ROOT /公/系統/ exterior_image /:附件/:id_partition /:款式/:文件名」