Retrieve data from post request

Hallo,

when I'm updating data the form, in development.log I get following:

Parameters: {"utf8"=>"✓",
"authenticity_token"=>"CoswtfwZJa2cUlwama/RcsWdxQWbUmRRzv6JbkfSUfw=",
"tbl_test"=>{"title"=>"Miller", "ref_recclass_id"=>"1",
"ref_reckat_id"=>"6", "ref_reckind_id"=>""}, "commit"=>"Save",
"id"=>"1"}

In the controller (update action), when I try to retrieve data from the
post request, I only can retrieve the value of the id with @test =
params[:id]), but not for example the value of ref_reckind_id with @test
= :ref_reckind_id.

Do somone have any suggestion how to retrieve the values of the other
attributes?

Thanks ahead!!

Regs

Herman

Hallo,

when I'm updating data the form, in development.log I get following:

Parameters: {"utf8"=>"✓",
"authenticity_token"=>"CoswtfwZJa2cUlwama/RcsWdxQWbUmRRzv6JbkfSUfw=",
"tbl_test"=>{"title"=>"Miller", "ref_recclass_id"=>"1",
"ref_reckat_id"=>"6", "ref_reckind_id"=>""}, "commit"=>"Save",
"id"=>"1"}

In the controller (update action), when I try to retrieve data from the
post request, I only can retrieve the value of the id with @test =
params[:id]), but not for example the value of ref_reckind_id with @test
= :ref_reckind_id.

Since ref_reckind_id is nested inside tbl_test you will have to use
something like
params[:tbl_test][:ref_recking_id]

Colin

The :ref_reckind_id key is inside a hash that is itself inside the params hash.

Try this:

params[:tbl_test][:ref_reckat_id].

But typically, you will not use this formulation directly, rather code like:

tbl_test = TblTest.find(params[:id])
if tbl_test.update_attributes(params[:tbl_test]) # here the “internal” hash is supplied to update_attributes)
# success
else
# handle failure

end

HTH,

Peter

Found the solution by myself:

@test = [:tbl_test][:ref_recclass_id]

then @test = 6

Thank you Peter,

I didn't refreshed my browser since I posted my question.

So I found your solution after i found it by myself.

I think, if I refreshed it earlier, I have saved two hours work.
Regs

Herman

Thank you Peter,

and Colin …

I didn’t refreshed my browser since I posted my question.

So I found your solution after i found it by myself.

I think, if I refreshed it earlier, I have saved two hours work.

… but you learned a lot more by searching it yourself :slight_smile:

Peter