2011-02-09 82 views
0
irb(main):001:0> e = Event.last 
=> #<Event id: 7, address: "123 Main St", start_date: "2011-02-09", start_time: "2000-01-01 14:49:00", title: "Test Event", poster_file: "\377���JFIF\000\001\002\000\000d\000d\000\000\377�Ducky\000\001\000\004\000\000\0002\000\000\377�!Adobe\000d�...", poster_thumb_file: nil, created_at: "2011-02-09 14:49:45", updated_at: "2011-02-09 14:49:45", poster_file_name: nil, poster_content_type: "image/jpeg", poster_file_size: 134218, poster_updated_at: "2011-02-09 14:49:44"> 
irb(main):002:0> e.poster.url 
=> "/posters/original/missing.png?1297262984" 

我使用Pat Shaughnessy的回形針寶石的叉子。我也嘗試過,並且發現了另一個發現here的叉子的相同問題,所以我很確定這只是我做了一些愚蠢的事情。我的應用程序託管在heroku上。 我跟着誰最初分叉的回形針和努力去適應他們到Rails 3.我對海報的路線是這樣的人the instructions回形針DB存儲:附件進去,但不出來

resources :events do 
    member do 
    get :poster 
    end 
end 

,並在控制器中,我有:

class EventsController < ApplicationController  
    downloads_files_for :event, :poster 
... 
end 

和型號:

class Event < ActiveRecord::Base 
    attr_accessor :poster_thumb_file, :poster_file_name 
    has_attached_file :poster, :storage => :database, :styles => {:thumb => { :geometry => "100x100>", :column => 'poster_thumb_file'}} 
end 

我想不通我缺少什麼讓這些圖像顯示。任何意見,將不勝感激!

回答

0

嘗試複數的「海報」在你的路由文件:

resources :events do 
    member do 
    get :posters 
    end 
end 

的downloads_files_for方法假定在URL中的多個附件的名稱;請參閱:https://github.com/patshaughnessy/paperclip/blob/master/lib/paperclip/storage/database.rb#L190

如果要在URL中使用「海報」而不是「海報」,則必須手動編寫控制器操作。基本上它只是Event.find ...然後用event.poster.file_contents調用send_data並傳遞類型和文件名。

這個問題修復了嗎? - 拍

+0

感謝您回答帕特。由於某種原因,它仍然不起作用。我可以在DB中看到他們。到目前爲止距離很近...... – mikewilliamson 2011-02-09 20:43:59