0

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?

Community
  • 1
  • 1
Working Title
  • 254
  • 7
  • 28

2 Answers2

4

You have two underscore characters in def fetch__records.

Steve
  • 6,334
  • 4
  • 39
  • 67
1

It looks like your method definition has two underscores while you are calling only one:

def fetch__records

And

rails runner "Procedure.fetch_records"

Change either the def to fetch_records or the runner to fetch__records

ScottJShea
  • 7,041
  • 11
  • 44
  • 67