# Using request.env to persist data?

**URL:** <https://www.ruby-forum.com/t/using-request-env-to-persist-data/159353>\
**Category:** Rails\
**Created:** [February 3, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/using-request-env-to-persist-data/159353 "2009-02-03T19:47:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatyree](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f14d63/32.png) [@tatyree](https://www.ruby-forum.com/u/tatyree)\
**Post date:** [February 3, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/using-request-env-to-persist-data/159353/1 "2009-02-03T19:47:32Z")

</div>

Is it ever sensible to attempt to persist data across a session using  
request.env? Say something like:

request.env[‘user\_name’] = ‘bob’

I’m discussing this with the maintainer of a commercial gem (where it  
doesn’t seem to work).

My natural instinct would be to do this instead (indeed, I patched the  
gem):

session[:user\_name] = ‘bob’

I’m guessing that his use of request.env is derived from experience in  
another language (PHP?) and I just wanted to check that it wasn’t some  
obscure, but reasonable, railsian way of doing things (that wasn’t  
working on any of my three environments) before I went back to him.

Cheers,  
Todd

---

<div class="post-metadata">

**Author:** ![tatyree](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f14d63/32.png) [@tatyree](https://www.ruby-forum.com/u/tatyree)\
**Post date:** [February 3, 2009, 7:55pm UTC](https://www.ruby-forum.com/t/using-request-env-to-persist-data/159353/2 "2009-02-03T19:55:50Z")

</div>

On 3 Feb 2009, at 18:47, tatyree wrote:

> Is it ever sensible to attempt to persist data across a session using  
> request.env? Say something like:
> 
> request.env[‘user\_name’] = ‘bob’
> 
> I’m discussing this with the maintainer of a commercial gem (where it  
> doesn’t seem to work).

Nope not a chance in hell. The request environment last for the  
duration of the request.

> My natural instinct would be to do this instead (indeed, I patched the  
> gem):
> 
> session[:user\_name] = ‘bob’

That’s what I would

---

<div class="post-metadata">

**Author:** ![tatyree](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f14d63/32.png) [@tatyree](https://www.ruby-forum.com/u/tatyree)\
**Post date:** [February 3, 2009, 8:01pm UTC](https://www.ruby-forum.com/t/using-request-env-to-persist-data/159353/3 "2009-02-03T20:01:14Z")

</div>

Thank Frederick,

> Nope not a chance in hell. The request environment last for the  
> duration of the request.

That’s exactly what I though.

Cheers,  
Todd

---

<div class="post-metadata">

**Author:** ![tatyree](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f14d63/32.png) [@tatyree](https://www.ruby-forum.com/u/tatyree)\
**Post date:** [February 4, 2009, 12:46am UTC](https://www.ruby-forum.com/t/using-request-env-to-persist-data/159353/4 "2009-02-04T00:46:45Z")

</div>

Across a session, or a request/response loop?

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)
