[英]Ruby on Rails Carrierwave - files uploaded owned by 'nobody'
[英]Ruby on Rails: Downloading files with multiple dots in filename (uploaded using Carrierwave)
風景:
<%= link_to File.basename(attachment.attachment.url), "/uploads/#{attachment.id}/#{File.basename(attachment.attachment.url)}" %>
控制器:
# ...
def download
path = "#{Rails.root}/uploads/"+ params[:id] + "/"+ params[:basename] +"."+ params[:extension]
send_file path, :x_sendfile=>true
end
# ...
路線:
match "/uploads/:id/:basename.:extension", :controller => "attachments", :action => "download", :conditions => { :method => :get }
得到的錯誤是:
Routing Error
No route matches [GET] "/uploads/38/Screen_shot_2012-02-18_at_2.20.49_PM.png"
match "/uploads/:id/:filename.:extension", :controller => "attachments", :action => "download", :constraints => { :filename => /[^\/]+/ }, :conditions => { :method => :get }
感謝forker,我被引導到這個博客: http ://coding-journal.com/rails-3-routing-parameters-with-dots/
match "/uploads/:id/:filename", :controller => "attachments", :action => download, :requirements => { :filename => /.*/ }
通過這篇博客文章
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.