Hey Doug,
i believe this is the line that was confusing you?
person_type.constantize.find(*args)
first, all of what i wrote was model code, and yes, you should break up
the two classes into two separate model files, or really, three:
Person.rb, Client.rb, and Prospect.rb.
Ok, so in that one line, person_type is a string. rails mixes in a
function to the String class called “constantize” that changes a string
into an actual program token,
so, if person_type is “Client” then person_type.constantize is the
actual Programming token Client. As long as you define the Client
class, rails will then interpret the above line as
Client.find(*args)
OR
Prospect.find(*args)
depending on the string passed into abstract_find.
The reason i have *args is because it is what the ActiveRecord API
specificies as the argument to find - (basically all arguments passed to
ActiveRecord find are rolled up into an array, which it then figures out
what to do with)
so, the above code would allow you to, in your controller, say something
like,
@person = Person.abstract_find(“Client”, [normal find arguments go
here])
or
@person = Person.abstract_find(“Prospect”, [normal find arguments go
here])
the real power comes when you basically let the actual type be
dynamically determined by the program/user at run time:
@person = Person.abstract_find(specified_person_type, [normal find
arguments go here])
I know you had said that you had pretty much figured it out, but i
thought this might still be useful. hope it is!
-Gabe
Doug J. wrote:
6: � else
7: � � nil
8: � end
9: end
I really wish that I understood your suggestion especially because it
may be what works. I have taken the liberty of adding line numbers.
Basically, I understand the code except for line 5. I have no idea
what you are doing there. I’m not sure what the person_type and *args
are that you are passing to abstract_find. Part of my confusion may
stem from the fact that there does not seem to be and ‘end’ for your
class definition. So, I’m not altogether clear on whether lines 3
through 9 are suggested model code or suggested controller code.
Could you please clarify? I do appreciate your suggestion and I have
high hopes for it being my salvation. Thanks.
... doug