如下图,你的 URI 实际上是无效的。您的 URI 中不能有未转义的空格。
1.9.3p194 :001 > require 'URI' => true
1.9.3p194 :002 > URI.parse('http://localhost:3000/mycontroller/index.html#&panel1-2?error=Invalid Member ID and/or Date of Birth')
URI::InvalidURIError: bad URI(is not URI?): http://localhost:3000/mycontroller/index.html#&panel1-2?error=Invalid Member ID and/or Date of Birth
from /Users/ccashwell/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/common.rb:176:in `split'
from /Users/ccashwell/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/common.rb:211:in `parse'
from /Users/ccashwell/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/common.rb:747:in `parse'
from (irb):2
from /Users/ccashwell/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
您应该escape
使用 URI:
1.9.3p194 :003 > URI.escape('http://localhost:3000/mycontroller/index.html#&panel1-2?error=Invalid Member ID and/or Date of Birth')
=> "http://localhost:3000/mycontroller/index.html%23&panel1-2?error=Invalid%20Member%20ID%20and/or%20Date%20of%20Birth"
然后你可以redirect_to
转义的URI:
redirect_to URI.escape('http://localhost:3000/mycontroller/index.html#&panel1-2?error=Invalid Member ID and/or Date of Birth')