Rails 4 - request.original_fullpath 和 request.fullpath 有什么区别
Rails 4 - What is the difference between request.original_fullpath and request.fullpath
我需要将用户搜索查询存储在我们的数据库中以跟踪搜索历史记录。我知道 request.original_url 会给我一个绝对的查询字符串 url.
http://www.example.com/search?utf8=%E2%9C%93&keywords=cars&view=grid
我更喜欢存储相对 url 路径。话虽如此,对于具有所有参数的亲戚 url request.original_fullpath 和 request.fullpath[=29= 之间的区别是什么]?好像是同一个东西?
request.original_fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
request.fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
original_fullpath returns 一个包含最后请求路径的字符串,包括它们的参数。
fullpath returns 字符串完整路径,包括最后 URL 请求的参数。
original_fullpath
和 fullpath
的区别在于,original_fullpath
方法不包含原始 url 中没有的参数(即通过 POST 而不是 GET 发送。
我想添加 original_fullpath ignores redirects, while 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
我需要将用户搜索查询存储在我们的数据库中以跟踪搜索历史记录。我知道 request.original_url 会给我一个绝对的查询字符串 url.
http://www.example.com/search?utf8=%E2%9C%93&keywords=cars&view=grid
我更喜欢存储相对 url 路径。话虽如此,对于具有所有参数的亲戚 url request.original_fullpath 和 request.fullpath[=29= 之间的区别是什么]?好像是同一个东西?
request.original_fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
request.fullpath
/search?utf8=%E2%9C%93&keywords=cars&view=grid
original_fullpath returns 一个包含最后请求路径的字符串,包括它们的参数。
fullpath returns 字符串完整路径,包括最后 URL 请求的参数。
original_fullpath
和 fullpath
的区别在于,original_fullpath
方法不包含原始 url 中没有的参数(即通过 POST 而不是 GET 发送。
我想添加 original_fullpath ignores redirects, while 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