Topic: Dinamically getting data types ?

Hello,

I'm quite new to rails and I would like to know if there is any way to dynamically find the type of one data-base column. Do anyone know about this ?

thanks,

Ravenala.

Re: Dinamically getting data types ?

Hi,

an ActiveRecord class has a columns method which returns a list of all columns of the class and a lot of information on each of the colums. so for example:

>> User.columns[1]
=> #<ActiveRecord::ConnectionAdapters::MysqlColumn:0x34bceec @limit=255, @null=true, @name="login", @primary=false, @type=:string, @scale=nil, @sql_type="varchar(255)", @original_default=nil, @default=nil, @precision=nil>


hope that helps.
maze

Re: Dinamically getting data types ?

Hi,

Works fine,

I use : MyActiverecordObject.column_for_attribute(MyColumnName).type.to_s

Thanks for help !