Search code examples
ruby-on-railsrubyrunner

Undefined method in runner


So I've been trying to test the following simple script title procedure.rb

class Procedure < ActiveRecord::Base
  def fetch__records
    selection = connection.execute("SELECT * From users  WHERE name = test AND password = password")

    if (selection != nil)
      puts "It works."
    else
      puts "It fails."
    end
  end
end

Which just sends a simple SQL select statement to a users table and And yet every time I run

rails runner "Procedure.fetch_records"

I get the following error

  undefined method `fetch_records' for Procedure(Table doesn't exist):Class (NoMethodError)

I took a look at this question and changed it that fetch_records is defined as

def self.fetch_records

But I still received the same error. Why is it saying fetch_records in undefined?


Solution

  • You have two underscore characters in def fetch__records.