Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Module function from Controller (NoMethodError)

So I have a module "MiddleMan" I am able to call it just fine in the rails console but in the controller I am getting a NoMethodError

In the controller I have:

class SignUpController < ApplicationController
  include MiddleMan
  def page_one
      @package = MiddleMan::read_catalog("a", "b", "c")
  end
end

And in the middleman.rb module I have:

module MiddleMan
  def read_catalog(package, payment, coupon)
    Package.new(:price => "4.99")
  end
end

Any thoughts?

like image 688
Msencenb Avatar asked Jul 06 '11 23:07

Msencenb


1 Answers

Since you included the module the instance method read_catalog is added to your Class, so you can call it directly:

class SignUpController < ApplicationController
  include MiddleMan
  def page_one
      @package = read_catalog("a", "b", "c")
  end
end
like image 149
Wizard of Ogz Avatar answered Nov 08 '22 23:11

Wizard of Ogz