# Need to clean params

**URL:** <https://www.ruby-forum.com/t/need-to-clean-params/106209>\
**Category:** Rails\
**Created:** [June 7, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/need-to-clean-params/106209 "2007-06-07T16:29:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![P.V.Anthony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@P.V.Anthony](https://www.ruby-forum.com/u/P.V.Anthony)\
**Post date:** [June 7, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/need-to-clean-params/106209/1 "2007-06-07T16:29:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![P.V.Anthony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@P.V.Anthony](https://www.ruby-forum.com/u/P.V.Anthony)\
**Post date:** [June 7, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/need-to-clean-params/106209/2 "2007-06-07T16:39:37Z")

</div>

Hi there,

Just do the next:

params.delete(:participant)

---

<div class="post-metadata">

**Author:** ![P.V.Anthony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@P.V.Anthony](https://www.ruby-forum.com/u/P.V.Anthony)\
**Post date:** [June 7, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/need-to-clean-params/106209/3 "2007-06-07T16:41:38Z")

</div>

On 6/7/07, P.V.Anthony [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![P.V.Anthony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@P.V.Anthony](https://www.ruby-forum.com/u/P.V.Anthony)\
**Post date:** [June 7, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/need-to-clean-params/106209/4 "2007-06-07T16:48:39Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)
