使用GET/POST参数将Rails重定向到"www.somewebsite.com"?

Lou*_*ePr 5 ruby ruby-on-rails http-status-code-301 http-status-code-302

我正在尝试在我的一个控制器中发出redirect_to到一个完全限定的URL +我想传递一些参数

在网站AI的控制器中:

redirect_to: "www.siteB.com/my_controller/my_action?my_parameter=123"
Run Code Online (Sandbox Code Playgroud)

在rails中有更好的方法吗?

Den*_*ssy 6

如果SiteB运行相同的应用程序(即该服务器的路由相同),那么您可以构建您描述的重定向:

redirect_to :host => "www.siteB.com", 
            :controller => "my_controller", 
            :action => "my_action",  
            :my_parameter => 123
Run Code Online (Sandbox Code Playgroud)

请注意,未处理的任何键都会url_for自动编码为参数.


Fra*_*itt 1

您显然可以通过主机:

redirect_to { :host => "www.siteB.com", :controller => "my_controller", :action => "my_action",  :id => 123 }
Run Code Online (Sandbox Code Playgroud)

查看 的文档url_for