我已經創建了控制器/關注一個問題叫做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
我做錯了什麼?
你重新啓動Rails嗎? –