On Thu, Sep 11, 2008 at 11:40 PM, Ashley Moran <
[EMAIL PROTECTED]> wrote:

>
>
>
> > and this, which generates the entry fields for a form. I usually
> > only load it when I need it, and it works with our css conventions
> > so you may need to mangle it. Note that it assumes you are using my
> > lookup codes plugin that still hasn't made it to github.
>
> What's this lookup codes plugin?
>
>
In the olden days we used integer codes for things that came in lists, like,
say job titles or bank names. It's a good idea, particularly if you want to
be able to change the string representation without scanning every
occurrence in your database and replacing it, just change the text and
everything changes. It also saves on storing lots of strings everywhere
which can help with storage.

You have a lookup codes table with a domain column that defines what the
lookup is for. The plugin lets you do this:

class Applicant < ActiveRecord::Base
# ...
  has_lookup_code( {
    :title                => 'Person Title',
    :time_to_call         => 'Time to call',
    :occupation           => 'Occupation',
    :employment_type      => 'Employment Status',
    :credit_rating        => 'Credit Status',
    :residential_status   => 'Residential Status',
    :marital_status       => 'Marital Status',
    :property_style       => 'Property Style',
    :phone_one_type       => 'Phone Type',
    :phone_two_type       => 'Phone Type',
  } )
# ...
end

The symbol is the column name, the string is the arbitrary domain name (can
be anything).

This adds some class-level methods, for example there will be
Applicant.title_list, Applicant.sorted_title_list and
Applicant.title_lookup.

The first two let you do this in  your views:

        <label for="applicant_title">Title <span
class="required">*</span></label>
        <%= f.select :title, Applicant.sorted_title_list, {}, :class =>
'select' %>

The last one lets you turn the integer into the string by using a hash. The
plugin adds a convenience method, e.g. title_str, that gives you the string
value for an instance.

By convention id 0 is 'Please select' and this is always first in the sorted
list.

At the class level I also now have

>> Applicant.title_<tab>
Applicant.title_dr             Applicant.title_mrs
Applicant.title_list           Applicant.title_ms
Applicant.title_lookup         Applicant.title_other
Applicant.title_miss           Applicant.title_please_select
Applicant.title_mr             Applicant.title_rev

This lets me refer to the codes by name without having to do any magic
number hacking.

Lookup codes are also cached after their first access (on a production
database).

I need a few hours to write it so it installs and so on. Will try to find
time this weekend.

Like I said, I need a couple of hours to do this. We've been using this code
forever at Marketrix and it's pretty bomb proof.

-- 
Thanks and regards,

Francis Fish

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"NWRUG" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nwrug-members?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to