1
如果我想匹配x.gif
和y.gif
,是否有可能通過一個URL來map.connect
涵蓋的兩個文件名稱是這樣的可能性:map.connect是否接受URL中的通配符樣式格式?
map.connect "public/images/:name.gif",
:controller => "static_image_controller",
:action => "serve"
,然後接收param
在我StaticImageController
作爲params[:name]
?
class StaticImageController < ApplicationController
def serve
image_name = params[:name]
image = File.read(File.join(Rails.root, image_name))
send_data image, :type => "image/gif", :disposition => "inline"
end
end
除了我在這裏做的事實違反了Rais中的約定配置原則外,這看起來是正確的嗎?
最後一部分是什麼? (:filename => /\.gif$/) – pepe 2009-06-22 22:58:23
它表示對於要應用的路由,filename參數必須與regex /.gif$/匹配 – 2009-06-22 23:00:47