how to assignee each value to correspoding key while updat.

B

Bishnu Das

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.
 
B

Bishnu Das

Bishnu said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,290
Messages
2,571,452
Members
48,129
Latest member
DianneCarn

Latest Threads

Top