Bry*_*n.I 6 uri ruby-on-rails query-string ruby-on-rails-4
我需要在我们的数据库中存储用户搜索查询以跟踪搜索历史记录.我知道request.original_url会将查询字符串作为绝对URL.
http://www.example.com/search?utf8=%E2%9C%93&keywords=cars&view=grid
Run Code Online (Sandbox Code Playgroud)
我宁愿存储相对url路径.话虽如此,对于所有params的相对url,request.original_fullpath和request.fullpath之间有什么区别?他们似乎是一回事?
request.original_fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
Run Code Online (Sandbox Code Playgroud)
request.fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
Run Code Online (Sandbox Code Playgroud)
original_fullpath返回一个String,其中包含最后请求的路径,包括它们的参数.
fullpath返回String完整路径,包括请求的最后一个URL的params.
original_fullpath和之间的区别在于fullpath,original_fullpath方法不包括原始URL中没有的参数(即通过POST而不是GET发送的参数).
我想添加original_fullpath忽略重定向,而fullpath包含它们,例如:
# some_spec.rb
describe 'collections' do
before do
get '/collections'
end
context 'user is not signed in' do
it 'should redirect to /unauthenticated' do
expect(request.original_fullpath).to eq '/collections'
expect(request.fullpath).to eq '/unauthenticated'
end
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3331 次 |
| 最近记录: |