Распознавать маршрут с помощью регулярных выражений? - PullRequest
0 голосов
/ 22 сентября 2011

Допустим, у меня есть URL-адрес обратной передачи, который появляется как

http://domain/merkin_postback.cgi?id=987654321&new=25&total=1000&uid=3040&oid=123

, а иногда как:

http://domain/merkin_postback.php?id=987654321&new=25&total=1000&uid=3040&oid=123

Если мое определение маршрута

map.purchase '/merkin_postback', :controller => 'credit_purchases', :action => 'create'

он лает, что любая из двух вышеприведенных форм недопустима.

Должен ли я использовать регулярное выражение для распознавания любой из двух форм?

1 Ответ

0 голосов
/ 22 сентября 2011

Это не проблема маршрутизации, это проблема формата контента. Вы должны использовать respond_to.

class CreditPurchasesController < ActionController::Base
  # This is a list of all possible formats this controller might expect
  # We need php and cgi, and I'm guesses html for your other methods
  respond_to :html, :php, :cgi

  def create
    # ...
    # Do some stuff
    # ...

    # This is how you can decide what to render based on the format
    respond_to do |format|
      # This means if the format is php or cgi, then do the render
      format.any(:php, :cgi) { render :something }

      # Note that if you only have one format for a particular render action, you can do:
      #   format.php { render :something }
      # The "format.any" is only for multiple formats rendering the exact same thing, like your case
    end
  end
end
...