Uppercase all row columns

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

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

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.

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.

Thanks!

Pepe

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.

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. :slight_smile:

Pepe