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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi there, Just do the next: params.delete(:participant) P.V.Anthony wrote:> 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 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/7/07, P.V.Anthony <pvantony-rdc5FV7LBygPGFelY5Zqew@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <lukhnos-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 6/7/07, P.V.Anthony <pvantony-rdc5FV7LBygPGFelY5Zqew@public.gmane.org> 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. > > > >-- EPA Rating: 3000 Lines of Code / Gallon (of coffee) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---