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

发布于 2024-08-17 00:50:17 字数 199 浏览 2 评论 0原文

我正在尝试在我的一个控制器中发出一个重定向到完全限定的 URL + 我想

在站点 AI 的控制器中传递一些参数:

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

是否有更好的方法在 Rails 中执行此操作?

I'm trying to issue a redirect_to in one of my controllers to a fully qualified URL + I want to pass in some parameters

In the controller for site A I do:

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

Is there a nicer way to do this in rails?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

勿忘初心 2024-08-24 00:50:17

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

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

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

If SiteB is running the same app (i.e. the routes are the same for that server), then you can build the redirect you describe with:

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

Notice that any keys not handled by url_for are automatically encoded as parameters.

一口甜 2024-08-24 00:50:17

您显然可以传递主机:

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

查看 url_for

You can apparently pass a host:

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

Check out the documentation for url_for.

能否归途做我良人 2024-08-24 00:50:17

沿着其他回应的思路。如果您设置了一个在站点 A 的 paths.rb 中定义路径的控制器,则可以使用生成的 url 帮助程序。只需覆盖 :host 作为参数即可。

示例:

站点 A Routes.rb:

...
map.resource whatever
...

站点 A 控制器:

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

只要 SiteB 的 Web 服务器(rails 或其他)识别您的 http://www.siteB.com/whaterver/edit?my_parameter=123很好。

警告:请记住,使用 302 重定向帖子会产生RFC 2616。简而言之,这意味着在重定向的帖子成功之前,将要求用户重新确认他们的帖子到新的 URL。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文