5

コントローラーの 1 つで、redirect_to を完全修飾 URL に発行しようとしています + いくつかのパラメーターを渡したい

サイト AI のコントローラーで次のことを行います。

redirect_to: "www.siteB.com/my_controller/my_action?my_parameter=123"

レールでこれを行うより良い方法はありますか?

4

3 に答える 3

6

SiteB が同じアプリを実行している場合 (つまり、そのサーバーのルートが同じである場合)、次のように記述したリダイレクトを作成できます。

redirect_to :host => "www.siteB.com", 
            :controller => "my_controller", 
            :action => "my_action",  
            :my_parameter => 123

によって処理されないキーはurl_for、パラメーターとして自動的にエンコードされることに注意してください。

于 2010-01-07T00:35:57.887 に答える
1

Along the lines of the other responses. If you set up a controller defining the path in your routes.rb of site A, you can use the generated url helpers. Just override the :host as an argument.

Example:

Site A Routes.rb:

...
map.resource whatever
...

Site A Controller:

...
redirect_to edit_whatever_url(:host => "www.siteB.com", :my_parameter => 123)
...

So long as SiteB's web server (rails or otherwise) recognizes the http://www.siteB.com/whaterver/edit?my_parameter=123 you're good.

Caveat: Keep in mind that redirecting a Post with 302 has specific consequences as defined in RFC 2616. In a nutshell it means that a user will be asked to reconfirm their post to the new URL, before the redirected post can succeed.

于 2010-01-07T13:56:26.380 に答える
1

どうやらホストを渡すことができます:

redirect_to { :host => "www.siteB.com", :controller => "my_controller", :action => "my_action",  :id => 123 }

のドキュメントを確認してくださいurl_for

于 2010-01-07T00:32:00.523 に答える