Skip to content

Instantly share code, notes, and snippets.

@heartpunk
Created November 13, 2013 06:04
Show Gist options
  • Save heartpunk/7444464 to your computer and use it in GitHub Desktop.
Save heartpunk/7444464 to your computer and use it in GitHub Desktop.
class FieldType < ActiveRecord::Base
has_many :model_object_types
has_many :field_values
attr_accessible :name
end
class FieldValue < ActiveRecord::Base
has_one :field_type
has_many :object_models
attr_accessible :value
end
class ModelObjectType < ActiveRecord::Base
has_many :object_models
has_many :field_types
end
class ModelObject < ActiveRecord::Base
belongs_to :model_object_type
has_many :field_values
def method_missing(method, *args, &block)
field = self.model_object_type.field_types.detect { |f| f.name == method.to_s }
if(field)
self.field_values.where(:field_type_id => field.id).first.try(:get_value)
else
super
end
end
def respond_to?
# ???
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment