Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>the relevant 2 lines:</p> <p><a href="https://github.com/ernie/meta_search/blob/master/lib/meta_search.rb#L55" rel="nofollow">https://github.com/ernie/meta_search/blob/master/lib/meta_search.rb#L55</a></p> <p><a href="https://github.com/ernie/meta_search/blob/master/lib/meta_search/searches/active_record.rb#L46" rel="nofollow">https://github.com/ernie/meta_search/blob/master/lib/meta_search/searches/active_record.rb#L46</a></p> <p>I don't think it is a bug, it is just how things are. </p> <p>in scenario 3 In development environment, you do not preload the model. When you require 'meta_search', it will define 'search' on <code>ActiveRecord::Base</code>. Then you say <code>Document</code>, which loads the model, will first inherit defined search method so when it includes Tire search module, it will leave search aliased to metasearch.</p> <p>In production mode (scenario 4) as well as scenario 2, you preload the document model before metasearch so Tire will define search. Now requiring metasearch will only have effect on newly loaded classes.</p> <p>You can see that the order in which gems are defined does not count. But you can undefine search method after gem require.</p> <pre><code># application.rb # ... Bundler.require(:default, Rails.env) if defined?(Bundler) # now move search out of the way ActiveRecord::Base.instance_eval { undef :search } </code></pre> <p>so any time later we load a model class and include tire, search will correctly go to tire, both in development and production.</p> <p>This is not ideal since the search method for non-tire models will not delegate to metasearch, in fact it will not be defined. So probably the second solution is best: here you overwrite the search method with one which checks for tire at runtime:</p> <pre><code>class ActiveRecord::Base def self.search(*args, &amp;block) if respond_to?(:tire) tire.search(*args, &amp;block) else metasearch(*args, &amp;block) end end end </code></pre> <p>does this help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload