Jens Kraemer wrote:
> On Thu, May 10, 2007 at 12:48:15PM +0200, Allen Young wrote:
>> >
>> There are about 100 attributes reside in several different tables. That
>> means I need to define all this methods manually?
>
> that depends - some metaprogramming might help make it a less daunting
> task.
>
> i.e.
>
> class OtherClass
> # define which fields you want to have indexed and how:
> def ferret_fields
> { :field1 => { :store => :yes }, ... }
> end
> end
>
> class MyModel
> # collect field list for aaf
> ferret_fields = { :name => {}, ... }
> ferret_fields.update! OtherClass.ferret_fields
>
> acts_as_ferret :fields => ferret_fields
>
> # define getters
> OtherClass.ferret_fields.keys.each do |field|
> define_method :"ferret_#{field}" do
I think this should be :"#{field}" or I must define ferret_feilds = {
:ferret_field1 } in OtherClass instead.
> other_object.send(field)
> end
> end
> end
>
It seems that define_method doesn't work at all. I got many errors
saying that there is no method defined for things like ferret_field1. I
even tried to define a simple method dynamically with the following
code at the class level of my model class.
define_method :say_hello { puts 'hello' }
But unexpectedly, method_missing is called, so it means that
define_method doesn't work. Is there anything wrong about my using with
define_method?
allen
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk