Note that there are some explanatory texts on larger screens.

plurals
  1. POFind Stuff (but not in production)
    primarykey
    data
    text
    <p>Using the tutorial "Find Stuff (quick and Dirty)" in "Advance Rails Recipes", I can find stuff in the development environment but not in the production environment. </p> <pre><code>NoMethodError: undefined method `searchable_by' </code></pre> <p>I have this code in "lib/searchable.rb"</p> <pre><code>module Searchable def searchable_by(*_column_names) @search_columns = [] [column_names].flatten.each do |name| @search_columns &lt;&lt; name end end def search(query, fields=nil, options={}) with_scope :find =&gt; { :conditions =&gt; search_conditions(query, fields) } do find :all, options end end def search_conditions(query, fields=nil) return nil if query.blank? fields ||= @search_columns words = query.split(",").map(&amp;:split).flatten binds = {} or_frags = [] count = 1 words.each do |word| like_frags = [fields].flatten.map { |f| "LOWER(#{f}) LIKE :word#{count}" } or_frags &lt;&lt; "(#{like_frags.join(" OR ")})" binds["word#{count}".to_sym] = "%#{word.to_s.downcase}%" count += 1 end [or_frags.join(" AND "), binds] end end </code></pre> <p>and this in my 'config/initializers/core_extensions.rb'</p> <pre><code>ActiveRecord::Base.extend Searchable </code></pre> <p>I have roamed the internet and found people saying that if I change config.cache_classes to false then it should work: but it doesn't.</p> <p>I've never tried using extra scripts in my apps, so I'm probably missing out something pretty basic here.</p> <p>Any help will be appreciated!</p> <p><em>UPDATE: Additional Info</em></p> <p>I specify this in the model (app/models/candidate.rb)</p> <pre><code>class Candidate &lt; ActiveRecord::Base searchable_by :first_name, :surname, :experience, :skills, :looking_for, :hours_required, :location, :more_details end </code></pre> <p>And I call it in the controller (app/controllers/candidates_controller.rb)</p> <pre><code>class CandidatesController &lt; ApplicationController def index @candidates = Candidate.visible end def search @candidates = Candidate.visible.search(params[:q]) end end </code></pre> <p>(visible is just a named_scope)</p> <p>Any help would be really appreciated.</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. 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