لا map.connect قبول صيغة على غرار البدل في URL؟
-
06-07-2019 - |
سؤال
إذا أريد لمطابقة على x.gif
وy.gif
، أو غير ذلك من الممكن تمرير URL إلى map.connect
التي تشمل إمكانيات كل من أسماء شيئا من هذا القبيل:
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
وبالإضافة إلى حقيقة أن ما أقوم به هنا يخالف مبادئ الاتفاقية على التكوين في الريس، هل هذا تبدو صحيحة؟
المحلول
map.connect '/public/images/:filename', :filename => /\.gif$/
وسوف نفعل ذلك.
لا تنتمي إلى StackOverflow