# How to assignee each value to correspoding key while updat

**URL:** <https://www.ruby-forum.com/t/how-to-assignee-each-value-to-correspoding-key-while-updat/134471>\
**Category:** Ruby\
**Created:** [April 11, 2008, 6:08am UTC](https://www.ruby-forum.com/t/how-to-assignee-each-value-to-correspoding-key-while-updat/134471 "2008-04-11T06:08:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bishnubapi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d07c76/32.png) [@bishnubapi](https://www.ruby-forum.com/u/bishnubapi)\
**Post date:** [April 11, 2008, 6:08am UTC](https://www.ruby-forum.com/t/how-to-assignee-each-value-to-correspoding-key-while-updat/134471/1 "2008-04-11T06:08:11Z")

</div>

Hi all

```
  **--my problem is that i get key and value .but i have to save in

```

the database. but while saving it will save only one key and  
corresponding value ,but if i want to save more than one value to  
corresponding keys ,it shows problems.  
My code is like this:-

local\_keys = @params.keys  
first\_addition = true  
param\_value =0  
sql=String.new  
sql\_value=String.new  
for key in 0…local\_keys.length  
list=key.methods  
key\_name = local\_keys[key]  
value = @params[key\_name]  
puts "key "+key\_name.to\_s+ " value "+value.to\_s  
if key\_name!=“action” && key\_name!=“controller”  
@test\_runs = TestRuns.new  
@test\_run.ks=value(it is successful)(here ks is my column  
name)  
but when i want to update more than one it is not successfull  
like  
@test\_run.ps=value(:-here ps is column name )  
@test\_run.ts=value (:-here ts is column name)  
@test\_run.ls=value (:-here ls is column name)  
can i do it in a generic way.if anybody knows please help me in this  
regard.

```
but any how i got all the keys and values .only my problem is how i

```

assignn each key to value.it should be in genric way.i have search it  
but i do not get the right way.

---

<div class="post-metadata">

**Author:** ![bishnubapi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d07c76/32.png) [@bishnubapi](https://www.ruby-forum.com/u/bishnubapi)\
**Post date:** [April 11, 2008, 2:29pm UTC](https://www.ruby-forum.com/t/how-to-assignee-each-value-to-correspoding-key-while-updat/134471/2 "2008-04-11T14:29:28Z")

</div>

Bishnu Das wrote:

> Hi all
> 
> ```
> **--my problem is that i get key and value .but i have to save in
> 
> ```
> 
> the database. but while saving it will save only one key and  
> corresponding value ,but if i want to save more than one value to  
> corresponding keys ,it shows problems.  
> My code is like this:-
> 
> local\_keys = @params.keys  
> first\_addition = true  
> param\_value =0  
> sql=String.new  
> sql\_value=String.new  
> for key in 0…local\_keys.length  
> list=key.methods  
> key\_name = local\_keys[key]  
> value = @params[key\_name]  
> puts "key "+key\_name.to\_s+ " value "+value.to\_s  
> if key\_name!=“action” && key\_name!=“controller”  
> @test\_runs = TestRuns.new  
> @test\_run.ks=value(it is successful)(here ks is my column  
> name)  
> but when i want to update more than one it is not successfull  
> like  
> @test\_run.ps=value(:-here ps is column name )  
> @test\_run.ts=value (:-here ts is column name)  
> @test\_run.ls=value (:-here ls is column name)  
> can i do it in a generic way.if anybody knows please help me in this  
> regard.
> 
> ```
> but any how i got all the keys and values .only my problem is how i
> 
> ```
> 
> assignn each key to value.it should be in genric way.i have search it  
> but i do not get the right way.

final solution is

@test\_runs[:"#{key\_name}"] = value

this will directly save in the database .  
note:-@test\_run is my table name  
Thanks Mr Balaji for his kind solution.
