如果我想匹配x.gif
andy.gif
,是否可以传递一个map.connect
包含两个文件名可能性的 URL,如下所示:
map.connect "public/images/:name.gif",
:controller => "static_image_controller",
:action => "serve"
param
然后在我StaticImageController
的 as中收到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 中约定优于配置的原则之外,这看起来对吗?