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)
On 6/7/07, P.V.Anthony [email protected] 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.
I do the following:
class Hash
def pass(*keys)
tmp = self.clone
tmp.delete_if {|k,v| ! keys.include?(k) }
tmp
end
def block(*keys)
tmp = self.clone
tmp.delete_if {|k,v| keys.include?(k) }
tmp
end
end
On 6/7/07, Lukhnos D. Liu [email protected] wrote:
For example is there a way to do something like this.
(note that it’s not :participant_name but rather name, assuming that’s
the name of the column)
d.
–
EPA Rating: 3000 Lines of Code / Gallon (of coffee)