2013-10-16 73 views
1

我有一个控制器调用模型方法:为什么我的模型被识别为模块?

class WelcomeController < ApplicationController 
    item_num = params[:item_num] || "0001" 
    @product = Scraper.lookup_item(item_num) 
end 

这里是Scraper型号:

class Scraper < ActiveRecord::Base 
    require 'nokogiri' 
    require 'mechanize' 

    def self.lookup_item(item_num) 
    # code goes here 
    end 
end 

为什么会出现这个错误?

NoMethodError: undefined method 'lookup_item' for Scraper:Module

+1

你的'''config/application.rb'''中是否有一行'''模块Scraper'''? 没有发布答案,因为我只有90%的把握。 – mechanicalfish

回答

1

我以前也遇到了这个错误。 grep您的项目,以查看是否在任何地方定义了module Scraper。如果是,请删除它,或将其更改为类而不是模块。

+1

我是一个完全白痴。我的整个项目被称为刮刀,所以是它的定义无处不在哈哈。 – trevorhinesley

相关问题