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 }
Thanks to forker I was led to this blog: http://coding-journal.com/rails-3-routing-parameters-with-dots/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With