map.connect是否在URL中接受通配符样式的格式? [英] Does map.connect accept a wildcard-style format in the URL?

查看:105
本文介绍了map.connect是否在URL中接受通配符样式的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我要匹配 x.gif y.gif ,则为可以将URL传递给 map.connect ,其中包含两个文件名的可能性,如下所示:

If I want to match x.gif and y.gif, is it possible to pass a URL to map.connect that encompasses the possibilities of both filenames something like this:

map.connect "public/images/:name.gif",
  :controller => "static_image_controller",
  :action => "serve"

然后接收 param 在我的 StaticImageController 中作为 params [:name] 吗?

And then receive the param in my 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

除了我在做什么

推荐答案

map.connect '/public/images/:filename', :filename => /\.gif$/

会做到这一点。

这篇关于map.connect是否在URL中接受通配符样式的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆