Working Title
Working Title

Reputation: 254

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?

Upvotes: 0

Views: 621

Answers (2)

ScottJShea
ScottJShea

Reputation: 7111

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

Upvotes: 1

Steve
Steve

Reputation: 6424

You have two underscore characters in def fetch__records.

Upvotes: 4

Related Questions