开发者

NameError when using act_as_ferret

开发者 https://www.devze.com 2022-12-30 15:19 出处:网络
I am getting this error when I am using acts_as_ferret :fields =>[:competitor], :remote => true NameError in PartController#index

I am getting this error when I am using

acts_as_ferret :fields =>[:competitor], :remote => true

NameError in PartController#index

uninitialized constant PartController::Competitor

My Model

class Competitor < ActiveRecord::Base
  validates_presence_of :fee_earner_id, :notes
  belongs_to :fee_earner 
  belongs_to :country 
  belongs_to :state 
  belongs_to :user
  acts_as_ferret :fields =>[:competitor], :remote => true
end  

My controller

class PartController < ApplicationController
  def index
    @proscribeds = Competitor.paginate(:all, 
                                       :order => sort , 
                                       :page => params[:page], 
                      开发者_如何学Go                 :per_page => 70 )
  end 
end

Its working fine in localhost but when I deploy it in the server than I get this error.

act_as_ferret is working good with other models. I don't know why this is not working with only Competitor model.


These might seem like simplistic suggestions, but here's what comes to mind:

  • Do you have the same OS on localhost and the server? I've been burned by little discrepancies like the differences between how Unix and Windows handle mixed case pathnames.
  • Have the most updated versions of all your files been moved? Can you do a diff and ensure that there isn't a missing config file or environment variable or something?

I know those suggestions aren't really Rail/Ruby-specific, but I've found that little configuration problems tend to give me more headaches than actual code errors do.

Good luck!


This could be a problem with the bin/ferret_server file on the remote drb server you are running. What it is complaining about is that it knows nothing about the PartController::Competitor model. This is because the ferret-server does not eager load all the Rails classes like Rails does by default.

I had a similar issue and the solution was to also require the Rails config/environment file as well as the Rails config/application file.

Something like this:

begin
  ENV['FERRET_USE_LOCAL_INDEX'] = 'true'
  if env = $ferret_server_options['environment']
    ENV['RAILS_ENV'] = env
  end

  # determine RAILS_ROOT unless already set
  root = File.expand_path(determine_rails_root)

  begin
    require File.join(root, 'config', 'application')
    # Also require environment to eager load Rails classes
    require File.join(root, 'config', 'environment')
  rescue
    puts "Error booting your rails app at #{root}: #{$!}\n#{$!.backtrace.join("\n")}"
    raise $!
  end

  puts "Rails.root: #{Rails.root}"
  puts "Rails.env: #{Rails.env}"

  require 'acts_as_ferret/server/server'
  ActsAsFerret::Server::Server.new.send($ferret_server_action)
rescue Exception => e
  $stderr.puts(e.message)
  $stderr.puts(e.backtrace.join("\n")) if $ferret_server_options['debug']
  exit(1)
end
0

精彩评论

暂无评论...
验证码 换一张
取 消