简体   繁体   English

Ruby on Rails:下载文件名中包含多个点的文件(使用Carrierwave上传)

[英]Ruby on Rails: Downloading files with multiple dots in filename (uploaded using Carrierwave)

The view: 风景:

<%= link_to File.basename(attachment.attachment.url), "/uploads/#{attachment.id}/#{File.basename(attachment.attachment.url)}" %>

The controller: 控制器:

# ...
  def download
    path = "#{Rails.root}/uploads/"+ params[:id] + "/"+ params[:basename] +"."+ params[:extension]

    send_file path, :x_sendfile=>true
  end
# ...

The route: 路线:

match "/uploads/:id/:basename.:extension", :controller => "attachments", :action => "download", :conditions => { :method => :get }

The error is get is: 得到的错误是:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM