Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Undefined Method include when including a module in `lib` dir

I cannot load my PactHelper module from my lib dir.

# lib/pact_helper.rb

module PactHelper
    def so_something

    end
end

and

# app/controllers/registrations_controller.rb

class RegistrationsController < ApplicationController

    include PactHelper

    def new
        ...
    end
end

returns undefined method 'include' for #<RegistrationsController:0x5287cf8>

Could someone explain to me why my module is not being included?

like image 458
Harry Avatar asked Mar 13 '26 05:03

Harry


1 Answers

Try:

require 'pact_helper.rb'

Above:

class RegistrationsController < ApplicationController

In:

registrations_controller.rb

like image 191
John Avatar answered Mar 14 '26 20:03

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!