Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7721487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:56:14+00:00 2026-06-01T03:56:14+00:00

Hi there I have 3 files in rails as follows: 1)Located at app/controller/listings_controller.rb class

  • 0

Hi there I have 3 files in rails as follows:
1)Located at “app/controller/listings_controller.rb”

class ListingsController < ApplicationController

  def index   
    #Construct kd Tree in memory
    @tree = Listing.constructKDTree;
    @tree.inspect
  end

2) Located at app/models/listing.rb

require 'kd_tree.rb'
class Listing < ActiveRecord::Base

  def constructKDTree
    @contents = self.all

    @kdTree = KDTree.new(@contents) 

  end

3) Located at app/models/kd_tree.rb

class KDTree

  def initialize (db_listings)
    'Initializing Tree' 

  end

end

Now I’m trying to test the method implementation for constructKDTree so I went to my rails console and tried the following commands:

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

But I get this error:

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>'

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:56:15+00:00Added an answer on June 1, 2026 at 3:56 am

    You defined constructKDTree as an instance method on Listing. Thus the method is only available on instances of the class but nit the class itself.

    Depending on what you actually want to achieve, you can make the method a class method like it’s done in the following code, or you could create a new instance of the Listing class and call the method on the instance.

    class Listing < ActiveRecord::Base
      def self.constructKDTree
        @contents = self.all
        @kdTree = KDTree.new(@contents) 
      end
    end
    

    However looking at the code you have there, you probably want to do the latter and create a new instance of the class:

    listing = Listing.new
    @tree = listing.constructKDTree
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have there been incompatibilities between Java releases where Java source code/Java class files targeting
I have a rails 3 app using paperclip. Is there a way with paperclip
Say I have two files where there is one number per line File 1
I have two files which both contain a list of words. Is there an
I have 2 files, main.html and search.php . Within the main.html page, there is
I have many js files, with some naming convention. If there any tool that
I have developed an application that read how many files are there in a
I have a simple file browser and there I display files and folders, obtained
Is there a way to have Expression Language (EL) expressions included JavaScript files be
I have a system where employees can upload files. There are three ways Upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.