I am having some problem with my image route, because it does not get the image file ending in params.
Here is my route:
match '/photographer/ima开发者_JAVA技巧ge/:id/:filename' => 'application#photore'
And my controller:
def photore
redirect_to "http://s3-eu-west-1.amazonaws.com/mybucket/photographer/image/#{params[:id]}/#{params[:filename]}"
end
I need the filending because else amazon S3 wont load the image.
aNoble is going in the right direction, the Rails format handling is probably eating the extension but it is also probably throwing it away because it isn't .html
, .js
, or any of the other extensions that it understands. Try setting some constraints on the :filename
in your route:
match '/photographer/image/:id/:filename' => 'application#photore', :constraints => { :filename => /.*/ }
That should allow the extension to be left as part of params[:filename]
.
Assuming you're running Rails 3.1, I believe what you're looking for is params[:format]
. This functionality changed from 3.0 to 3.1 but didn't seem to be very well documented.
Try this:
def photore
redirect_to "http://s3-eu-west-1.amazonaws.com/mybucket/photographer/image/#{params[:id]}/#{params[:filename]}.#{params[:format]}"
end
Or you should be able to pass :format => false
to the match
method and keep your photore
method the same:
match '/photographer/image/:id/:filename' => 'application#photore', :format => false
精彩评论