One thing, I'm not sure if this is important or not.. Article is
defined in one plugin, and then another plugin is modifying Article.
So it's not as if there's an Article class underneath my rails_root,
everything is underneath vendor/plugins.

The whole basis for this is a pluggable blogging system I'm trying to
create, http://github.com/carpeliam/plogger which keeps the blog-
related models out of the app space. Article is defined in the plogger
plugin, and then modified in a plogger_thinking_sphinx plugin (http://
github.com/carpeliam/plogger_thinking_sphinx) to include searching.

On Jan 16, 8:14 pm, Liam Morley <[email protected]> wrote:
> Pat, thanks very much for the reply. Defining the index as a variable
> and then calling "Article.send :define_index, &index" had the same
> effect as calling it with index inline: I'm still getting "undefined
> method `define_index' for #<Class:0x6d8d380>".
>
> I figured I'd just require 'thinking_sphinx' inside of the plugin
> itself (although I thought that TS would have already been required
> from environment.rb? I thought that all gems were always loaded before
> all plugins? Confusing):
>
> require 'thinking_sphinx'
>
> class Article
>   define_index do
>     indexes title
>     indexes description
>     indexes post
>     has created_at
>     set_property :delta => true
>   end
> end
>
> This works fine, BUT with one significant hitch. I'm using the
> "devise" gem for authentication (http://github.com/plataformatec/
> devise), and when I use the above code, my authentication routes
> disappear-- but ONLY in production mode. This baffles the hell out of
> me. `rake routes` returns all of my auth routes, but `rake routes
> RAILS_ENV=production` does not. I don't receive any error messages.
> The routes only disappear when I make the call to define_index; if I
> require 'thinking_sphinx' but don't call define_index, I still see the
> routes.
>
> This only happens when adding define_index to Article from within a
> plugin- all of the devise routes work just fine in production if
> define_index is called in RAILS_ROOT/app/models/article.rb.
>
> So it seems like there's still some problem calling define_index from
> within a plugin. I'm not sure if it's because define_index gets called
> at the bottom of Article, and I have no idea why any of this would
> throw the devise gem off, and still only in production.
>
> I'm not quite sure if this is the right forum to ask anymore, but I'm
> not sure if this is a rails problem, a TS problem, a devise problem,
> or a personal problem. :) I appreciate any insight anyone might have,
> though.
>
> Liam
>
> On Jan 14, 7:47 pm, Pat Allan <[email protected]> wrote:
>
> > Hi Liam
>
> > I've just tried your second approach below, it failed for me as well. What 
> > *should* work is defining the block first, then calling it as an argument 
> > for define_index:
>
> >   index = lambda do
> >     # ...
> >   end
> >   Article.send :define_index, &index
>
> > Hope this helps.
>
> > --
> > Pat
>
> > On 14/01/2010, at 12:35 AM, Liam Morley wrote:
>
> > > I'm working on a plugin that adds ThinkingSphinx to a model, and I'm
> > > learning a lot about Ruby's metaprogramming in the process.
>
> > > I've learned that although I can open my model and add to it without a
> > > problem, this starts to break down if I try to add anything to it that
> > > isn't defined in the Ruby libraries (ie, 'has_many', or
> > > 'define_index'). Adding has_many was easy
> > > (Article.send :has_many, :comments), but I'm not sure how to proceed
> > > for define_index.
>
> > > Here's what I'm starting with:
>
> > > class Article < ActiveRecord::Base
> > >  define_index do
> > >    indexes title, :sortable => true
> > >    indexes description
> > >    indexes post
> > >  end
> > > end
>
> > > I imagine that would take the form of Article.send(:define_index,
> > > &some_block) but the tricky part for me seems to be in defining
> > > some_block. I'm not sure how to go about doing this. I tried the
> > > following:
>
> > > Article.send :define_index, lambda do
> > >  indexes title, :sortable => true
> > >  indexes description
> > >  indexes post
> > > end
>
> > > but received "tried to create Proc object without a block". I tried:
>
> > > Article.send :define_index, &(lambda do
> > >  indexes title, :sortable => true
> > >  indexes description
> > >  indexes post
> > > end)
>
> > > but received "undefined method `define_index' for #<Class:0x6d8d380>",
> > > which is the same thing I get if I just re-open 'Article' and add a
> > > call to define_index in the first place. This code is at the far
> > > reaches of the map for me, both in terms of Ruby and of TS. Any ideas
> > > on the correct syntax for this sort of thing?
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Thinking Sphinx" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to 
> > > [email protected].
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/thinking-sphinx?hl=en.
-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.


Reply via email to