Does map.connect apply the template format in the url?

If I need to map and , is it possible to pass the URL to , which includes the capabilities of both file names something like this: x.gify.gifmap.connect

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

And then get paramin my StaticImageControllerhow 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 the convention over configuration in Rais, does this look right?

+1
source share
1 answer
map.connect '/public/images/:filename', :filename => /\.gif$/

will do it.

+3
source

Source: https://habr.com/ru/post/1781572/


All Articles