It works… Thank you for kind help. But, I am unable to use params[:id] to get the selected value from collection_select. how i can get selected value to params.
But, I am unable to use params[:id] to get the selected value
from collection_select. how i can get selected value to params.
I need the flow
collection_select (value selected) -> param[:id]-> find SQL row..
The selected value is in params already, just not where you're looking.
Take a look in your log at the post request that rails receives when you
submit the form... this information is all readily available there.
You should see something like:
Parameters: {"utf8"=>"blah1", "authenticity_token"=>"blah2",
"model_to_populate"=>{"column_to_populate"=>"blah3",...},
"commit"=>"blah4", "id"=>"blah5"}
In your controller code,
params[:id] is the id of the 'model_to_populate' (blah5)
params[:model_to_populate][:column_to_populate] is the value stored by
the collection_select statement in the view (blah3)
Parsing through and understanding your log files is something everyone
should be comfortable with. It's usually the first stop in performing
triage on unexpected behaviors.