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

On 28 February 2012 15:17, Herman Müller [email protected] wrote:

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


Posted via http://www.ruby-forum.com/.


You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


gplus.to/clanlaw

On Tue, Feb 28, 2012 at 4:17 PM, Herman Müller
[email protected]wrote:

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?

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

On Tue, Feb 28, 2012 at 6:28 PM, Herman Müller
[email protected]wrote:

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

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