What is the difference between 'env' and 'request.env' in Rails Controller?

醉酒当歌 提交于 2020-01-03 08:14:09

问题


I'm using rspec to write test for my application. In order to authorization I'm sending token in header:

request.headers['token'] = '000000099'
get :index

In controller side I can read this value by request.env["HTTP_TOKEN"] but env["HTTP_TOKEN"] is empty.

What is the difference between them and how can I set env instead of request.env?


回答1:


request.env is a ruby array that contains information about a visiting user’s and server environments. request.env is the standard object that's being used in Rails app to extract important information such as path_info, request_uri etc.

env is empty for your test because rspec-rails bypasses the ActionController::Metal dispatch method.



来源:https://stackoverflow.com/questions/33195258/what-is-the-difference-between-env-and-request-env-in-rails-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!