URL参数中的"+"由空格替换

Abh*_*ram 0 ruby url ruby-on-rails

我向rails发了一个ajax请求.URL是:

/learners/-638284588?is_combined_page=true&email=test0221k+staging@tt.com&type=ld"
Run Code Online (Sandbox Code Playgroud)

在日志中,我看到这些条目:

Started GET "/learners/-638284588?is_combined_page=true&    email=test0221k+staging@rosettastone.com&type=lcd" for 127.0.0.1 at Fri Feb 23 09:31:56 -0500 2018
Processing by Extranet::LearnersController#show as HTML
Parameters: {"type"=>"ld", "email"=>"test0221k staging@tt.com", "is_combined_page"=>"true", "id"=>"-638284588"}
[WARNING] Audit logging has been enabled for Account
parameter ----------------> {"type"=>"lcd", "email"=>"test0221k staging@tt.com", "controller"=>"extranet/learners", "is_combined_page"=>"true", "action"=>"show", "id"=>"-638284588"} test0221k staging@tt.com
Run Code Online (Sandbox Code Playgroud)

在URL中,email参数显示为:

email="test0221k+staging@tt.com"
Run Code Online (Sandbox Code Playgroud)

有一个+标志.但是当我从中读取参数时params[:email],它被打印为:

"email"=>"test0221k staging@tt.com"
Run Code Online (Sandbox Code Playgroud)

其中+由空格代替.

为什么rails会+用空格覆盖?我该如何避免这种情况"test0221k staging@tt.com"并获得"test0221k+staging@tt.com"

Bri*_*rty 6

这由URL规范定义.Rails刚刚确认了该规范.

在将参数放入URL之前,需要对参数进行编码.这样做的简单方法是调用encodeURIComponent()JavaScript.

表单会自动为您执行此编码.