Привет, у меня есть 3 файла в рельсах следующим образом:
1) Расположен в "app / controller / lists_controller.rb"
class ListingsController < ApplicationController
def index
#Construct kd Tree in memory
@tree = Listing.constructKDTree;
@tree.inspect
end
2) Расположен в app / models / list.rb
require 'kd_tree.rb'
class Listing < ActiveRecord::Base
def constructKDTree
@contents = self.all
@kdTree = KDTree.new(@contents)
end
3) Расположен в app / models / kd_tree.rb
class KDTree
def initialize (db_listings)
'Initializing Tree'
end
end
Теперь я пытаюсь проверить реализацию метода для constructKDTree
, поэтому я подошел к своей консоли rails и попробовал следующие команды:
1.9.2-p290 :001 > @lc = ListingsController.new
=> #<ListingsController:0x00000104f3e288 @_routes=nil, @_action_has_layout=true, @_headers={"Content-Type"=>"text/html"}, @_status=200, @_request=nil, @_response=nil>
1.9.2-p290 :002 > @lc.index
Но я получаю эту ошибку:
NoMethodError: undefined method `constructKDTree' for #<Class:0x00000104b1f760>
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
from /Users/AM/Documents/RailsWS/cmdLineWS/Businesses/app/controllers/listings_controller.rb:20:in `index'
from (irb):2
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Что я делаю не так?