2010-10-13 45 views
0

現在我試圖上傳一個pdf文件到服務器,但我什麼也沒得到,當我嘗試 獲取附件的url時,我得到了一些missing.png文件名。 有什麼我可以設置告訴回形針,我只是想上傳PDF文件,但 不是圖片? 非常感謝...這裏是我的課程設置回形針是否支持rails3?我怎樣才能支持上傳PDF文件?

============================================model file 
class RdBenefit < ActiveRecord::Base 
    belongs_to :reim_detail 
    has_attached_file :details 
    validates_attachment_content_type :doc, :content_type => ['application/doc'] 
end 

======================================schema 
    create_table "rd_benefits", :force => true do |t| 
    t.integer "sequence" 
    t.date  "reim_date" 
    t.integer "fee_time_span" 
    t.integer "people_count" 
    t.decimal "amount",    :precision => 10, :scale => 0 
    t.integer "reim_detail_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "details_file_name" 
    t.string "details_content_type" 
    t.integer "details_file_size" 
    t.datetime "details_updated_at" 
    end 


==========================gemfile 
gem "paperclip" 


=========================view file 
<%= form_for @doc_head,:remote=>true,:html => { :multipart => true } do |f| %> 
+0

一切,我的配置是作爲文檔的一樣,我只是想PDF或DOC文件不是圖片上傳文件...謝謝 – 2010-10-13 10:11:37

回答

1

回形針與Rails3一起使用。

如果你想你的附件限制只是PDF的,你應該建立驗證你的附件這樣的:

validates_attachment_content_type :pdf, :content_type => ['application/pdf'] 
+0

好這裏是我的班,但它不起作用 – 2010-10-13 13:09:15

+0

什麼不工作? – 2010-10-13 15:41:44

+0

我找不到任何錯誤消息,我沒有上傳文件在我的公共目錄 – 2010-10-14 00:43:28

0

你這裏的問題是:遠程=>真。看來你不能通過XHR請求上傳文件。

+0

謝謝本,我正在使用一個框架來解決這個問題。 – 2010-12-21 00:58:21

1

使用

gem 'remotipart', '~> 1.2' 

寶石,如果你要通過AJAX