Rails redirect_to "www.somewebsite.com" with GET / POST options?

I am trying to pass redirect_to in one of my controllers to the full URL + I want to pass 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 better way to do this on rails?

+5
source share
3 answers

If SiteB runs the same application (i.e. the routes are the same for this server), you can create the redirection that you describe using

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

Please note that any keys that are not processed url_forare automatically encoded as parameters.

+6
source

, , :

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

url_for.

+1

. , route.rb A, URL. : host .

:

A Routes.rb:

...
map.resource whatever
...

Site A Controller:

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

- SiteB ( ) http://www.siteB.com/whaterver/edit?my_parameter=123, .

: , Post 302 , RFC 2616. , URL-, .

+1

All Articles