Search code examples
ruby-on-railsnomethoderroractivesupport-concern

ClassMethods in Controller Concern returning NoMethodError


I have created a concern in controllers/concerns called reports.rb

In it I created the ClassMethods module.. It looks like this

module Reports
  extend ActiveSupport::Concern

included do
    require 'peddler'
    require 'csv'
end

module ClassMethods

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

I included this concern in my Merchants controller like this:

class MerchantsController < ApplicationController
  include Reports

And then tried to call the report_details method in an action on the Merchants controller like so:

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

According to this post Rich on Rails I should be able to call:

Merchant.report_details(xx,xxx,xxxx)

But I get a NoMethodError when I try.. I also tried:

me.report_details(xx,xxx,xxxx)

And got the same NoMethodError

What did I do wrong?


Solution

  • Try this

    MerchantController.report_details(xx,xxx,xxxx)
    

    But you should better include this concern in model.