dissecting params to read data

i have a simple form with a drop down menu that is created via another
model. when the user hits submit i have all the data passed thru but
can not extract it properly

form_for :user do |form|
form fields here....
find from another table with another model that creates a drop down
with form name "form2"
end

data shows

{"user"=>{"user_zid"=>"8780743182",
"minitial"=>"",
"lname"=>"doe",
"fname"=>"joe",
"password"=>"xxxxx",
"email"=>"foo@bar.com"},
"form2"=>{"important_data"=>"043"},
"commit"=>"Register!",
"authenticity_token"=>"d494c16b36637012c4d9d333a6045f3d4a0394cc"}

i tried:

@user = params[:user]
and then
need_data = @user.form2[:important_data]

help!

@user['form2'][:important_data]

Does this work?

no. You have a nil object when you didn't expect it!

i have tried @user.form2[:important_data]
undefined form2 ....

Hi --

i have a simple form with a drop down menu that is created via another
model. when the user hits submit i have all the data passed thru but
can not extract it properly

form_for :user do |form|
form fields here....
find from another table with another model that creates a drop down
with form name "form2"
end

data shows

{"user"=>{"user_zid"=>"8780743182",
"minitial"=>"",
"lname"=>"doe",
"fname"=>"joe",
"password"=>"xxxxx",
"email"=>"foo@bar.com"},
"form2"=>{"important_data"=>"043"},
"commit"=>"Register!",
"authenticity_token"=>"d494c16b36637012c4d9d333a6045f3d4a0394cc"}

i tried:

@user = params[:user]
and then
need_data = @user.form2[:important_data]

As S. Ross said, you would need @user[:form2][:important_data]. But
also remember that you can do:

   <% form_for :user do |form| %>
     <%= form.text_field .... %>
     <% fields_for :user2 do |form2| %>
       <%= form2.text_field .... %>
     <% end %>
   <% end %>

and then you'll have params[:user] and params[:user2] separately.

David

From your dump of params, you should be able to get your info using:

params['user']['form2']['important_data']

Nested params take some care because symbols can only be used to select the first level of the hash (IIRC). String keys always work, but the kewl kidz don't use them :wink:

Hi --

<% form_for :user do |form| %>
<%= form.text_field .... %>
<% fields_for :user2 do |form2| %>
<%= form2.text_field .... %>
<% end %>
<% end %>

and then you'll have params[:user] and params[:user2] separately.

i tried all the solution but i am getting - You have a nil object when
you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

i did read about fields_for and also saw it implemented on
railscast.com but i not sure how to implement with a drop down menu.
thanks for all the suggestions

wish it did but just wouldn't

just to make sure i did

@finally = params['user']['form2']['important_data']

but get nil, request parameters show as per my first post.

My mistake. I read the form2 as part of the user form, but now see that it is a completely different one. Or at least that's what I deduce from the naming. In any case, the immediate solution to your problem is to use:

params['form2']['important_data']

YEEEEEESSSSSSSSS!
it worked thanks so much for the help ross and david. this was my
first post on the group. thanks again.