Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails如何获取以params结尾的文件。png,.jpg_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails Rails如何获取以params结尾的文件。png,.jpg

Ruby on rails Rails如何获取以params结尾的文件。png,.jpg,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我的图像路由有一些问题,因为它没有得到以params结尾的图像文件 这是我的路线: match '/photographer/image/:id/:filename' => 'application#photore' 和我的控制器: def photore redirect_to "http://s3-eu-west-1.amazonaws.com/mybucket/photographer/image/#{params[:id]}/#{params[:filename]}" end

我的图像路由有一些问题,因为它没有得到以params结尾的图像文件

这是我的路线:

match '/photographer/image/:id/:filename' => 'application#photore'
和我的控制器:

def photore
  redirect_to "http://s3-eu-west-1.amazonaws.com/mybucket/photographer/image/#{params[:id]}/#{params[:filename]}"
end

我需要文件处理,否则AmazonS3不会加载图像

假设您运行的是Rails 3.1,我相信您需要的是。此功能从3.0更改为3.1,但似乎没有很好的文档记录

试试这个:

def photore
  redirect_to "http://s3-eu-west-1.amazonaws.com/mybucket/photographer/image/#{params[:id]}/#{params[:filename]}.#{params[:format]}"
end
或者您应该能够传递到
match
方法,并保持
photo
方法不变:

match '/photographer/image/:id/:filename' => 'application#photore', :format => false

aNoble正在朝着正确的方向发展,Rails格式处理可能正在吞噬扩展,但它也可能将其丢弃,因为它不是
.html
.js
,或者它理解的任何其他扩展。尝试在路由中的
:filename
上设置一些约束:

match '/photographer/image/:id/:filename' => 'application#photore', :constraints => { :filename => /.*/ }

这应该允许将扩展名作为
params[:filename]

的一部分,我使用的rails 3.0.9应该是:match'/摄影师/image/:id/:filename.:format?我没有找到匹配的路径“/pathor/image/55/Sk_-urbillede_2011-08-18_-kl.\u 14.34.58.png”是因为当时的“.”?在路由中,我有match'/photopher/image/:id/:filename.:format'我相信
match'/photopher/image/:id/:filename.:extension
,然后
params[:extension]
会起作用。最好避免使用
:format
,以免将来发生冲突。此外,您还应该能够执行请求全局搜索:
match/photopher/image/:id/*filename
,然后像最初一样使用
params[:filename]
。仍然可以获得无路由匹配我已批准Muu答案