【问题标题】:Undefined method in runner跑步者中未定义的方法
【发布时间】:2012-04-01 07:20:10
【问题描述】:

所以我一直在尝试测试以下简单的脚本标题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

它只是向用户表发送一个简单的 SQL 选择语句,但每次我运行时

rails runner "Procedure.fetch_records"

我收到以下错误

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

我查看了this question 并将其更改为 fetch_records 定义为

def self.fetch_records

但我仍然收到同样的错误。为什么在 undefined 中显示 fetch_records?

【问题讨论】:

    标签: ruby-on-rails ruby runner


    【解决方案1】:

    def fetch__records 中有两个下划线字符。

    【讨论】:

    • 我有复数问题,每次都踢自己。
    【解决方案2】:

    看起来你的方法定义有两个下划线,而你只调用一个:

    def fetch__records
    

    rails runner "Procedure.fetch_records"
    

    将 def 更改为 fetch_records 或将 runner 更改为 fetch__records

    【讨论】:

      猜你喜欢
      • 2015-10-10
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      相关资源
      最近更新 更多