Brad Chase wrote:> The legacy db I am currently working with has lots of codes (2 character
> strings) that are required to be the same in the new version of the app.
> Things like country codes, language codes and others which are not
> standard. Rather than create a table for each and then have a
> relationship between my models, I would much prefer to have a string
> field in the model being tagged with a code, limit user input via a
> select box and validate against the codes. Is there a pre-existing
> facility in rails for this? If not, where would be the best place to
> store these arrays of codes. I imagine writing some sort of plugin, say
> acts_as_limited_options, which when applied to a column and specified
> with the array to validate against, adds a custom validation against the
> array and adds a method to get the array of options for use in a select
> box. Does this make sense?
>
> Thanks.
AWDWR has an example of limiting user selections on a screen in the
PAYMENT_TYPES hash. It may be in different places depending on the
edition, but in the second edition the example is in Chapter 10, "Task
E: Checkout!".
I agree that a table for these values is overkill, unless they are
constantly being updated. A hash should do the job well.
I hope you can adapt this example to your needs.
Sean
--
Posted via http://www.ruby-forum.com/.