ruby-on-rails-5 - 带有 url 查询参数选项的 Rails 5 redirect_back
问题描述
根据文档:
redirect_back(fallback_location:,allow_other_host:true,**args)
:fallback_location
- 将在缺少Referer
标题时使用的默认后备位置。
:allow_other_host
- 允许或禁止重定向到与当前主机不同的主机,默认为 true。
可以传递给 redirect_to 的所有其他选项都被接受为选项,并且行为是相同的。
并redirect_to
允许我通过将参数作为散列传递来将参数添加到 url
那么,为什么这些都不适合我:
redirect_back fallback_location: tasks_path, allow_other_host: false, syncing: true
redirect_back fallback_location: tasks_path, allow_other_host: false, { syncing: true }
redirect_back fallback_location: tasks_path, allow_other_host: false, options: { syncing: true }
redirect_back(fallback_location: tasks_path, allow_other_host: false, options: { syncing: true })
redirect_back(fallback_location: tasks_path, allow_other_host: false, syncing: true)
...以及我能想到的上述任何其他迭代。
所有这些(都是有效代码),只需在不添加参数的情况下返回我
我正在尝试实现此 URL:
(back_url or fallback_location) + '?syncing=true'
解决方案
如果您查看源代码,redirect_back
您会看到,它本质上使用redirect_to "whatever_url.com"
了方法的版本redirect_to
。
如果您检查redirect_to 的解释,您会发现在这个用例中您很遗憾无法传递任何参数。如果这是非常需要的,我想你可以重写redirect_back
将 params 选项附加到带有字符串连接的 url 的方法,但这似乎是一个令人讨厌的修复。
但是要回答您的问题-您想要实现的目标似乎是不可能的。
推荐阅读
- javascript - 显示谁断开了用户与语音通道的连接
- java - 如何使用 Redhat 插件从 VSCodium 运行 Java Gradle 项目?
- java - 播放音频而不将其保存在文件中
- android - Android App 可能占据整个屏幕
- git - Heroku push:我们必须提交 runtime.txt
- python - 计算属于巨型组件的节点比例(python,networkx)
- reactjs - 我如何将数据从承诺传递到反应中的道具
- javascript - 在js中添加动态标签
- c - cs50: pset1: credit: Stuck, 所有输入的卡都无效
- python - 在 T-SQL 和 Python 之间为 Unicode 字符生成 MD5 HASH