# Putting environment variables in DB

**URL:** <https://www.ruby-forum.com/t/putting-environment-variables-in-db/109026>\
**Category:** Rails\
**Created:** [July 10, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/putting-environment-variables-in-db/109026 "2007-07-10T18:54:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 10, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/putting-environment-variables-in-db/109026/1 "2007-07-10T18:54:17Z")

</div>

Hi!

I have another small question. I have an environment variable set in  
environment.rb. The line looks like…

ENV[‘username’] = ‘mike’

What I would like to do is store ‘mike’ in the database in my ‘login’  
column. In the controller, if I add this…

```
@response = Response.new
@response = Response.new(params[:response])
@response.login = ENV['username']
@response.save

```

It will add one record that’s the username and all the other columns  
blank. Then, it’ll add another record with all the data.  
Essentially, it’s adding two records. I used an example on this forum  
and it obviously didn’t work very well. 🙂

I was wondering if anybody had an idea of why I’m getting two  
records…and if there is a better way to do this.

Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 11, 2007, 9:42am UTC](https://www.ruby-forum.com/t/putting-environment-variables-in-db/109026/2 "2007-07-11T09:42:02Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hi!
> 
> I have another small question. I have an environment variable set in  
> environment.rb. The line looks like…
> 
> ENV[‘username’] = ‘mike’
> 
> What I would like to do is store ‘mike’ in the database in my ‘login’  
> column. In the controller, if I add this…
> 
> ```
> @response = Response.new
> @response = Response.new(params[:response])
> @response.login = ENV['username']
> @response.save
> 
> ```
> 
> It will add one record that’s the username and all the other columns  
> blank. Then, it’ll add another record with all the data.  
> Essentially, it’s adding two records. I used an example on this forum  
> and it obviously didn’t work very well. 🙂
> 
> I was wondering if anybody had an idea of why I’m getting two  
> records…and if there is a better way to do this.
> 
> Thanks!

why is the #new method called twice? it’s sufficient enough to call it  
once with the params[:response] hash  
?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 11, 2007, 4:14pm UTC](https://www.ruby-forum.com/t/putting-environment-variables-in-db/109026/3 "2007-07-11T16:14:58Z")

</div>

Beats me. I tried to take out the first one (@response =  
Response.new), but then it didn’t work and popped up with an error  
message.

What I’ve done instead was just place a hidden field in my view and  
have it record the username. I found a message in this group saying  
how you shouldn’t do this and how you should use the method that I  
used. But, unfortunately, it doesn’t work for me, and I can’t find  
the thread that explained what it was doing now. ☹

Mike

On Jul 11, 2:42 am, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
