Does map.connect accept a wildcard-style format in the URL?

与世无争的帅哥 提交于 2019-12-11 06:48:10

问题


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"

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

Besides the fact that what I am doing here violates the principles of convention over configuration in Rais, does this look right?


回答1:


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

will do it.



来源:https://stackoverflow.com/questions/1029783/does-map-connect-accept-a-wildcard-style-format-in-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!