Stuart Rackham wrote:
> Hi
>
> What is the be practice regards setting the index path dynamically?
>
> My application needs to switch indexes based on the logged in user, I
> put the following before_filter into my controller (the
> Document.index_dir method calculates the user's index path):
>
> before_filter { Document.ferret_configuration[:path] =
> Document.index_dir }
>
> It seems to work, the only rough edge is that the acts_as_ferret
> declaration immediately creates a spurious index directory rather than
> deferring until the index is actually accessed (and the index path
> known), this also means the index directory is not automagically
> created.
P.S. The above didn't quite work, needed to set index directory in two
places for it to function when adding to the index and searching:
In controller:
before_filter { Document.set_index_dir }
In the model:
# Set the Ferret index to that of the current users account.
def self.set_index_dir
# Two places are used internally by acts_as_ferret.
Document.ferret_configuration[:path] = Document.index_dir
Document.configuration[:index_dir] = Document.index_dir
end
>
> Cheers, Stuart
> --
> Stuart Rackham
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk