![](/img/trans.png)
[英]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.