2011-09-22 143 views
0

比方说,我有进来的用正则表达式识别路由?

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 

如果我的路线定义为

它吠叫,要么的以上两种形式无效。

我应该使用正则表达式来识别两种形式之一吗?

+0

我不认为你可以这样调用:create操作,这是由于Rails惯例(不积极,但我似乎记得几年前遇到问题)。尝试使用不同的名称创建新操作。另外,我认为.php和.cgi可能不适合路由。我将路线更改为domain/merkin_postback /:id – jschorr

回答

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 
+0

但请注意@ james_schorr的注释 - 您可能无法通过这种方式映射到“创建”,可能是选择其他操作的好主意。 –

+0

啊,有道理。谢谢您的帮助。 – keruilin