#124 open
Jens

A patch allowing for dynamic fields

Reported by Jens | February 13th, 2010 @ 12:43 AM

I've added an option to acts_as_ferret to allow for dynamic fields. The option is

:dynamic_field
and it's value should be a symbol which references an instance method. The named method should return a hash with (field, value) pairs (field should be a symbol).

Example:

  acts_as_ferret(

:fields => [:title, :original_filename, :category],
:dynamic_fields => :metadata_fields



)
def metadata_fields
fields = Hash.new
metadata_responses.each do |r|
  name = r.metadata_name.name.to_sym
  value = r.value
  if fields[name].nil?
    fields[name] = value
  else
    fields[name] << " #{value}"
  end
end
fields



end
It doesn't appear that the SVN is working, I've been using
acts_as_ferret_trunk_20061012.tgz
. Instead of giving a patch I'll just post the code in here since it's short.

Add these lines to instance_methods.rb in the

to_doc
function (line 120 in my version)


      # Load dynamic documentation if supplied
      if configuration[:dynamic_fields]
        dynamic_fields = send configuration[:dynamic_fields]
        dynamic_fields.each do |field, value|
          doc[field] = value
        end
      end



Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket

Tags

Pages