From: Bishnu Das Date: 2008-04-11T21:29:29+09:00 Subject: Re: how to assignee each value to correspoding key while up 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. -- Posted via http://www.ruby-forum.com/.