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的fork的同样的问题,所以我很确定这只是我做了一些愚蠢的事情。我的应用程序托管在heroku上。 我跟着最初分开回形针的人the instructions,并试图让它们适应Rails 3.我的海报路线如下:
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 :(得分: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并传递类型和文件名。
这是解决了吗? - 拍拍