Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 回形针数据库存储:附件进入,但不出来_Ruby On Rails_Paperclip - Fatal编程技术网

Ruby on rails 回形针数据库存储:附件进入,但不出来

Ruby on rails 回形针数据库存储:附件进入,但不出来,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,在控制器中,我有: resources :events do member do get :poster end end 模型: class EventsController < ApplicationController downloads_files_for :event, :poster ... end 我不知道我缺少什么来显示这些图像。任何建议都将不胜感激 在您的路线文件中尝试多张海报: class Event < ActiveRecor

在控制器中,我有:

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
downloads_files_for方法在URL中采用复数附件名;见:

如果您想在URL中使用海报而不是海报,那么您必须自己手动编写控制器操作。基本上这只是一个事件。找到。。。然后调用send_data with Event.poster.file_contents并传递类型和文件名


这个修好了吗帕特

谢谢你回答帕特。由于某种原因,它仍然不起作用。我可以在数据库里看到他们。这么近,但到目前为止…按照你建议的路线,我应该能够在url/events/posters/8?style=原创,对吗?我得到:没有路线匹配/事件/海报/8Nope-应该是/events/8/posters?style=原创,默认情况下,风格应该是原创的。你可以运行rake路由,看看路由模式是什么…我不确定是什么改变了。。。也许额外的s。。。当我转到/events/8/posters?style=original时,会弹出一个窗口下载jpeg图像。我猜是哑剧。e、 但poster.url仍然返回/posters/original/missing.png?1297284160。还没有,但仍在进步!嘿,迈克,对不起,这太难了。。。请随意粘贴/发送电子邮件给我足够的代码来复制,我会仔细看看。pat@patshaughnessy.net
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
resources :events do
  member do
    get :posters
  end
end