View :
<%= link_to File.basename(attachment.attachment.url), "/uploads/#{attachment.id}/#{File.basename(attachment.attachment.url)}" %>
Controller :
# ...
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/
关于ruby-on-rails - ruby rails : Downloading files with multiple dots in filename (uploaded using Carrierwave),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9360671/