2015-09-03 37 views
0

我已经创建了控制器/关注一个问题叫做reports.rbClassMethods在控制器关注返回NoMethodError

在这里面,我创建了ClassMethods模块。它看起来像这样

module Reports 
    extend ActiveSupport::Concern 

included do 
    require 'peddler' 
    require 'csv' 
end 

module ClassMethods 

    def report_details(token, marketplace_id, merchant_id) 
     #... 
    end 

我包括这种担忧在我的招商控制器是这样的:

class MerchantsController < ApplicationController 
    include Reports 

然后试着拨打report_details方法,像这样招控制器上的动作:

def pull_from_amazon 
    me = Merchant.find(params[:merchant_id]) 
    marketplace = me.marketplace 
    token = me.token 
    Merchant.report_details(token, marketplace, params[:merchant_id]) 
    redirect_to root_path 
end 

根据这个帖子Rich on Rails我应该能够调用:

Merchant.report_details(xx,xxx,xxxx) 

但我得到一个NoMethodError当我尝试。我也试过:

me.report_details(xx,xxx,xxxx) 

,并得到了相同NoMethodError

我做错了什么?

+0

你重新启动Rails吗? –

回答

1

试试这个

MerchantController.report_details(xx,xxx,xxxx) 

但是,你应该更好地包括在模型这个问题。

+0

我尝试了MerchantController.report_details,但它没有工作..但我确实包括在商人模型中的关注,然后使用Merchant.report_details,并工作!非常感谢! – ToddT

+0

@ToddT,你说你原来的问题是你说你把它包含在控制器中,所以Alex是对的,如果你在你的模型上做这件事,当然这会发生变化。考虑接受亚历克斯的答案。 – Leito