2012-05-31 78 views
1

我正試圖在服務器上使用Carrierwave並在客戶端上使用Uploadify來實現上傳器。從客戶端看來,它的所有工作和服務器上的記錄都保存在數據庫中,但物理上傳的文件永遠不會保存到文件系統。請記住,我是Rails的新手。Rails 3,Uploadify和Carierwave

這是我上傳:

class ShapefileUploader < CarrierWave::Uploader::Base 

    storage :file 

    # simple path for debugging 
    def store_dir 
    "uploads" 
    end 

end 

我的模型:

class DataRecord < ActiveRecord::Base 

    # not too sure if this belongs here at all, documentation is not too specific. 
    require 'carrierwave/orm/activerecord' 

    mount_uploader :shapefile, ShapefileUploader 

end 

有一兩件事我不完全從Carrierwave文檔明白的是關於確保您加載後加載CarrierWave部分你的ORM。我不完全明白它的意思。

我的控制器:

class DataRecordsController < ApplicationController 
skip_before_filter :verify_authenticity_token, :only => [:update, :create] 

    def index 
    @folder = Folder.find(params[:folder_id]) 
    @data_types = DataType.all 
    end 

    def create 
    data_record = DataRecord.new({:shapefile => params[:Filedata], :folder_id => params[:folder_id], :user_file_name => params[:Filename], :data_type_id => 6}) 
    data_record.save! 
    end 

    def update 

    end 

end 

從實際的文件創建操作旁白上傳我手動設置調試數據的其餘部分。

這一切似乎沒有任何錯誤的工作。

這裏是發佈數據:

Parameters: {"Filename"=>"id_rsa.pub", "Filedata"=>#<ActionDispatch::Http::UploadedFile:0x007fc67836eb88 @original_filename="id_rsa.pub", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"Filedata\"; filename=\"id_rsa.pub\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:/tmp/RackMultipart20120531-4919-147n4qu>>, "Upload"=>"Submit Query", "folder_id"=>"74"} 

SQL INSERT:

INSERT INTO "data_records" ("data_type_id", "folder_id", "shapefile", "status", "uploaded_date_time", "user_file_name", "validated", "validation_results", "validation_to_send") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id" [["data_type_id", 6], ["folder_id", 74], ["shapefile", "id_rsa.pub"], ["status", 0], ["uploaded_date_time", nil], ["user_file_name", "id_rsa.pub"], ["validated", 0], ["validation_results", nil], ["validation_to_send", nil]] 

我知道有問候一些問題閃爍下探cookies,但我想我已經解決此工作了調試目的通過跳過檢查創建操作上的真實性標記。我已將上傳文件夾的安全權限更改爲全球讀取/寫入。我在github上Carrierwave文檔遇到的另一個困惑是如下代碼:

u.avatar = File.open('somewhere') 

難道這需要?如果是這樣,爲什麼和它做什麼?

幫助將不勝感激。謝謝!

回答

1

想通了!上傳的文件將被放入/ public/uploads。可能是一個菜鳥的錯誤,但如果在文檔中更好地解釋這個錯誤會很好。