small medium large xlarge

Generic-user-small
11 Apr 2008, 08:37
Bishnu Prasadit pradipta Narayan Das (1 post)

Hi all

  **--my problem is that i get key and value .but i have to save in the data base   in a generic ways.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 i want to save in a generic ways. like
@test_runs.key_name= value.(it is not working )

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.

Samr_small_pragsmall
23 Apr 2008, 19:56
Sam Ruby (634 posts)

Try @test_runs.instance_variable_set("@#{key_name}", value)

You must be logged in to comment