Hi,
Please do bear with me as I am a newbie.
I have an index params from a form with 5 fields of the same name.
Most of the times all these fields will not be filled.
Is there a way to clean the params before we do anything with it?
For example is there a way to do something like this.
I am purely guessing here.
params[:participant].delete(:participant_name => "")
Please advice. Or some link that I can learn more from.
Did try googling and failed to find anything useful.
P.V.Anthony
Hi there,
Just do the next:
params.delete(:participant)
P.V.Anthony wrote:
Please do bear with me as I am a newbie.
I have an index params from a form with 5 fields of the same name.
Most of the times all these fields will not be filled.
Is there a way to clean the params before we do anything with it?
Hmm, why do you need 5 fields of the same name? Also, why do
you need to clean the params?
For example is there a way to do something like this.
I am purely guessing here.
params[:participant].delete(:participant_name => "")
I assume you're using something like <%= text_field "participant", "name" %>,
and if the name is blank, the key :name will not show up at all.
But if you really need to delete the key for some reason, use the Hash#delete
(which you can just do "ri" for that):
params[:participant].delete(:name)
(note that it's not :participant_name but rather name, assuming that's
the name of the column)
d.