假设我有一个以
形式出现的回传网址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'
它咆哮上述两种形式中的任何一种都是无效的。
我应该使用正则表达式来识别这两种形式中的任何一种吗?
答案 0 :(得分:0)
这不是路由问题,而是内容格式问题。您应该使用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