[英]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.