I tried to do this for a long time, but I can not get around it.
For URLs ending in .pdf, I want to asset_hostretrieve files locally.
So, I am doing the following in a file development.rb
config.action_controller.asset_host = Proc.new { |source,request|
source.format.to_s.match(/pdf/) ?
"file://#{Rails.root.join('public')}" :
"#{request.protocol}#{request.host_with_port}"
}
But it gives me errors like:
private method `format ', called for" / stylesheets / css3buttons / reset.css? 1304745651 ": String
Question
What is the best way in rails3 to determine the URL request format?
Update
I tried source, request.media_typeand request.format, but none of them extracted the PDF!
The logs are shown below. I have added debug statements for each of the three above.
config.action_controller.asset_host = Proc.new { |source, request|
print "Source: " + source
print "\n"
print "request.media_type: " + request.media_type
print "\n"
print "request.format: " + request.format
print "\n"
}
: /stylesheets/css 3buttons/ reset.css?1304745651 request.media_type: request.format: text/html : /stylesheets/css 3buttons/css3-github-buttons.css?1304745651 request.media_type: request.format: text/html : /stylesheets/application.css?1304780110 request.media_type: request.format: text/html : /stylesheets/button -basics.css?1303711277 request.media_type: request.format: text/html : /stylesheets/global.css?1304739877 request.media_type: request.format: text/html : /javascripts/jquery.js?1302484024 request.media_type: request.format: text/html : /javascripts/rails.js?1302488107 request.media_type: request.format: text/html : /javascripts/jquery.maskedinput.js?1302484474 request.media_type: request.format: text/html : /javascripts/application.js?1300318225 request.media_type: request.format: text/html : /javascripts/jquery.js?1302484024 request.media_type: request.format: text/html : /javascripts/rails.js?1302488107 request.media_type: request.format: text/html : /javascripts/formToWizard.js?1256698412 request.media_type: request.format: text/html : /javascripts/application.js?1300318225 request.media_type: request.format: text/html : /javascripts/jquery.js?1302484024 request.media_type: request.format: text/html : /javascripts/rails.js?1302488107 request.media_type: request.format: text/html : /javascripts/rails _validations.js request.media_type: request.format: text/html : /javascripts/application.js?1300318225 request.media_type: request.format: /html
GET "/medicalhistories/9.pdf" 127.0.0.1 08 17:00:15 -0400 2011
pdf index.html.erb :
<td><%= link_to "PDF", medicalhistory_path(medicalhistory, :format => "pdf")%></td>