Hi. I have to convert the contents of all columns to uppercase before creating a row. Is there an easy way to accomplish this so I don''t have to go one column at a time and upcase! it? Thanks. Pepe --~--~---------~--~----~------------~-------~--~----~ 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 have to convert the contents of all columns to uppercase before > creating a row. Is there an easy way to accomplish this so I don''t > have to go one column at a time and upcase! it?Right a before_save filter on your model to loop through each of the attributes and uppercase them (but only if they are strings!) -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That''s what I am doing right now. I have a before_save filter, but I am upcasing each one column individually. How would I loop through the attributes and check for the attribute type? Thanks. On Jul 10, 2:58 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > I have to convert the contents of all columns to uppercase before > > creating a row. Is there an easy way to accomplish this so I don''t > > have to go one column at a time and upcase! it? > > Right a before_save filter on your model to loop through each of the > attributes and uppercase them (but only if they are strings!) > > -philip--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 10, 2008, at 12:11 PM, pepe wrote:> > That''s what I am doing right now. I have a before_save filter, but I > am upcasing each one column individually. How would I loop through the > attributes and check for the attribute type?Something like this: p = Product.find(:first) p.attributes.each_pair do |k,v| puts "#{k} is a string" if v.is_a?(String) end name is a string description is a string sku is a string Now, this is in console so you''ll need to twittle ''p'' to use self and obviously change the attributes instead of printing something out, but that''s the general idea.> On Jul 10, 2:58 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: >>> I have to convert the contents of all columns to uppercase before >>> creating a row. Is there an easy way to accomplish this so I don''t >>> have to go one column at a time and upcase! it? >> >> Right a before_save filter on your model to loop through each of the >> attributes and uppercase them (but only if they are strings!) >> >> -philip > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks! Pepe On Jul 10, 3:36 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Jul 10, 2008, at 12:11 PM, pepe wrote: > > > > > That''s what I am doing right now. I have a before_save filter, but I > > am upcasing each one column individually. How would I loop through the > > attributes and check for the attribute type? > > Something like this: > > p = Product.find(:first) > p.attributes.each_pair do |k,v| > puts "#{k} is a string" if v.is_a?(String) > end > name is a string > description is a string > sku is a string > > Now, this is in console so you''ll need to twittle ''p'' to use self and > obviously change the attributes instead of printing something out, but > that''s the general idea. > > > On Jul 10, 2:58 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: > >>> I have to convert the contents of all columns to uppercase before > >>> creating a row. Is there an easy way to accomplish this so I don''t > >>> have to go one column at a time and upcase! it? > > >> Right a before_save filter on your model to loop through each of the > >> attributes and uppercase them (but only if they are strings!) > > >> -philip--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, I talked to fast. I tried it and after a little bit of research, what ''attributes'' generates is a hash with the name of the column and it''s content, not the column type. Any idea how I can get that information? Thanks. On Jul 10, 3:36 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Jul 10, 2008, at 12:11 PM, pepe wrote: > > > > > That''s what I am doing right now. I have a before_save filter, but I > > am upcasing each one column individually. How would I loop through the > > attributes and check for the attribute type? > > Something like this: > > p = Product.find(:first) > p.attributes.each_pair do |k,v| > puts "#{k} is a string" if v.is_a?(String) > end > name is a string > description is a string > sku is a string > > Now, this is in console so you''ll need to twittle ''p'' to use self and > obviously change the attributes instead of printing something out, but > that''s the general idea. > > > On Jul 10, 2:58 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: > >>> I have to convert the contents of all columns to uppercase before > >>> creating a row. Is there an easy way to accomplish this so I don''t > >>> have to go one column at a time and upcase! it? > > >> Right a before_save filter on your model to loop through each of the > >> attributes and uppercase them (but only if they are strings!) > > >> -philip--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I think I got it:
e = Employee.new()
e.attributes.each_pair do |k,v|
puts "#{k} is a #{e.column_for_attribute(k).klass}"
end
LNAME is a String
FNAME is a String
DOB is a Date
Thanks so much! You put me in the right direction. :)
Pepe
On Jul 10, 5:15 pm, pepe <P...-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org>
wrote:> Sorry, I talked to fast. I tried it and after a little bit of
> research, what ''attributes'' generates is a hash with the
name of the
> column and it''s content, not the column type. Any idea how I can
get
> that information?
>
> Thanks.
>
> On Jul 10, 3:36 pm, Philip Hallstrom
<phi...-LSG90OXdqQE@public.gmane.org> wrote:
>
> > On Jul 10, 2008, at 12:11 PM, pepe wrote:
>
> > > That''s what I am doing right now. I have a before_save
filter, but I
> > > am upcasing each one column individually. How would I loop
through the
> > > attributes and check for the attribute type?
>
> > Something like this:
>
> > p = Product.find(:first)
> > p.attributes.each_pair do |k,v|
> > puts "#{k} is a string" if v.is_a?(String)
> > end
> > name is a string
> > description is a string
> > sku is a string
>
> > Now, this is in console so you''ll need to twittle
''p'' to use self and
> > obviously change the attributes instead of printing something out, but
> > that''s the general idea.
>
> > > On Jul 10, 2:58 pm, Philip Hallstrom
<phi...-LSG90OXdqQE@public.gmane.org> wrote:
> > >>> I have to convert the contents of all columns to
uppercase before
> > >>> creating a row. Is there an easy way to accomplish this
so I don''t
> > >>> have to go one column at a time and upcase! it?
>
> > >> Right a before_save filter on your model to loop through each
of the
> > >> attributes and uppercase them (but only if they are strings!)
>
> > >> -philip
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---