[英]passing # symbol to params hash in rails
我正在处理rails应用程序中的一些#标签处理。
告诉我们,我编写了一个端点,通过params
接收一个包含一些主题标签的字符串。 有些人喜欢这样
This string contains this #hashtag and this #one
。
我正在使用邮递员来测试我的终端。
现在,当我在邮递员中时,我会执行以下操作:
{{url}}/add?content=content=This string contains this #hashtag and this #one
我在params
收到字符串"content"=>"This string contains this "
。 也就是说,从符号#
的第一次出现开始,剩余的字符串被剪切掉。
非常清楚我的问题是天真的,我敢问为什么? 我做错了什么? 以及我如何管理传递包含#
符号的字符串?
你需要确保编码你在param中发送的任何内容。
URI.encode("This string contains this #hashtag and this #one")
#=> This%20string%20contains%20this%20%23hashtag%20and%20this%20%23one
更新邮递员请求以替换#
with %23
{{url}}/add?content=This string contains this %23hashtag and this %23one
在未来做这样的事情时,你可以选择则params的一部分(或整个事情),并点击右键并选择EncodeURIComponent
,如解释在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.