2015-09-03 78 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