Query the :limit => value back out of the schema

Railsters:

My evil colleagues could migrate the :limit=> on an important string at
any
time. (Think Twitter’s infamous string :limit => 140.)

I don’t want to guess that limit and hard-code it into the program; I
want to
read it back out of the ActiveRecord field properties. How to navigate
to them?


Phlip

Let’s say you have a model Foo, and you want the length of a column
“bar” - then this will do what you want:

Foo.columns.find { |c| c.name == ‘bar’ }.limit

–Matt J.

Matt J. wrote:

Foo.columns.find { |c| c.name == ‘bar’ }.limit

Tx it worked! And you can even set a “constant” on it…


Phlip