コントローラーの 1 つで、redirect_to を完全修飾 URL に発行しようとしています + いくつかのパラメーターを渡したい
サイト AI のコントローラーで次のことを行います。
redirect_to: "www.siteB.com/my_controller/my_action?my_parameter=123"
レールでこれを行うより良い方法はありますか?
コントローラーの 1 つで、redirect_to を完全修飾 URL に発行しようとしています + いくつかのパラメーターを渡したい
サイト AI のコントローラーで次のことを行います。
redirect_to: "www.siteB.com/my_controller/my_action?my_parameter=123"
レールでこれを行うより良い方法はありますか?
SiteB が同じアプリを実行している場合 (つまり、そのサーバーのルートが同じである場合)、次のように記述したリダイレクトを作成できます。
redirect_to :host => "www.siteB.com",
:controller => "my_controller",
:action => "my_action",
:my_parameter => 123
によって処理されないキーはurl_for
、パラメーターとして自動的にエンコードされることに注意してください。
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.
どうやらホストを渡すことができます:
redirect_to { :host => "www.siteB.com", :controller => "my_controller", :action => "my_action", :id => 123 }
のドキュメントを確認してくださいurl_for
。