Why is the env hash hanger empty in a Rails environment?

In my Rails application, I access the env hash in one of my controller actions.

Something along the lines of:

def my_before_filter env['some.key'] = "Something or other" end 

This is great for my requirements.

If I run the Rails application in a test environment and run an action like:

 # /users in UsersController#index def index puts env.inspect end 

Then the contents of the env hash are output to the console as expected.

When I get this action from the RSPec example, is the output an empty hash?

 it 'should get the index action' do get :index end .....{}.... # rspec output 

Why is env hash empty?

I created a dummy rails app to show this

+7
source share
1 answer

use

 request.env 

instead of env inside the controller code.

eg/

 def index puts request.env.inspect end 

Hope this helps?

BTW to another note: when working with your github registry, you need to remove public / index.html for your root route to work when the server starts.

+10
source

All Articles