加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – ruby?? – redirect_to(url,:myparam =>’

发布时间:2020-12-17 01:46:38 所属栏目:百科 来源:网络整理
导读:我无法解决这个问题. url = "www.mysite.com/?param1=abc"redirect_to(url,:param2 = 'xyz')### Should this go to - www.mysite.com/?param1=abcparam2=xyz 或者我错过了什么?它似乎不起作用? 解决方法 从 documentation: redirect_to(options = {},resp
我无法解决这个问题.

url = "www.mysite.com/?param1=abc"

redirect_to(url,:param2 => 'xyz')

### Should this go to - www.mysite.com/?param1=abc&param2=xyz

或者我错过了什么?它似乎不起作用?

解决方法

从 documentation:

redirect_to(options = {},response_status = {})

Redirects the browser to the target specified in options. This
parameter can take one of three forms:

Hash – The URL will be generated by calling url_for with the options.

Record – The URL will be generated by calling url_for with the
options,which will reference a named URL for that record.

String starting with protocol:// (like http://) or a protocol relative
reference (like //) – Is passed straight through as the target for
redirection.

你传递一个String作为第一个参数,所以它使用第三个选项.您的第二个参数被解释为response_status参数的值.

因此,如果您的重定向是内部重定向(到同一个应用程序),则无需指定方案和主机名.只是用

redirect_to root_url(param1 => 'abc',param2 => 'xyz')

如果是外部URL,请在重定向之前构建完整的URL:

url = "www.mysite.com/?param1=abc&params2=xyz"
redirect_to url

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读