2012-06-19 53 views
0

使用回形針時出現問題。 我可以看到上傳的文件,但現在我想要有一個下載鏈接,點擊它時下載「pdf文件」。下載上傳的文件paperclip

我看到這個例子:

<%= link_to "Download", model.whatever.url(:original, false) %> 

但我無法弄清楚如何使用我自己的看法和模型實現這一點。

希望有人能幫助我。

編輯:

這裏是我的模型:

class Contractgegeven < ActiveRecord::Base 

    has_attached_file :pdf 

    attr_accessible :bedrijfsonderdeel, :bestemd_voor, :betalingsgegevens, :betreft, :contractbeheerder, :contractduur, :einddatum, :ingangsdatum, :opzegtermijn, :soort_contract, :pdf 
    end 
+0

你可以發佈你的模型? –

+0

Didi你試試'Contractgegeven.last.pdf.url(:original)'? –

+0

我會嘗試:) –

回答

2

說你的模型是Image,你必須:

class Image < ActiveRecord::Base 
    has_attached_file :picture 

那麼你應該寫:

Image.last.picture.url(:original, false) 

不是Image.last.url(:original, false)

+0

我有我的模型貼在上面,我的模型有一個合同輸入字段的形式,現在我想添加合同的PDF格式,我想下載上傳的PDF格式,但是謝謝我會看到它的作品。 –

+0

感謝它的工作,因爲它應該,但現在它在瀏覽器中打開,並不下載它。有什麼問題? –

+0

很高興工作。爲了使它下載而不是在瀏覽器中打開,我想你必須使用['send_file(path,options = {})']來發送控制器中的文件(http://api.rubyonrails.org/classes /ActionController/DataStreaming.html#method-i-send_file)。但是,這是另一個故事;-) –