سؤال

إذا أريد لمطابقة على 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$/

وسوف نفعل ذلك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top