Wednesday, August 18, 2010

Rails, get column name of value

Programmer Question

This might be a little odd, but how can I get the column name from object in my model?



For example, I have a table which happens to have all 50 states in it as separate columns (I know, I know that could be way more efficient), so they look like:



al_allowed, ak_allowed, etc...


These columns are booleans, but I wanted to know in my model how to get the column names?, for example if for a particular record (in this case Campaigns), I want to see which states are checked off, and if they are True, I want to push the states abbreviation(the column name) into an array.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails