Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6012509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:24:53+00:00 2026-05-23T02:24:53+00:00

I have several different acts_as_… custom class methods I’d like to use in my

  • 0

I have several different acts_as_… custom class methods I’d like to use in my app. I would like the code for those methods to be in files in the app/modules directory.

I have been unable to get this working.

For instance, I have a file: app/modules/acts_as_lockable

module ActsAsLockable

    def acts_as_lockable
        before_create :set_lock

        include InstanceMethods
    end

    module InstanceMethods
        protected

        def set_lock
            now = Time.now.to_s
            self.lock = Digest::SHA1.hexdigest(now)
        end
    end

end

ActiveRecord::Base.extend ActsAsLockable

And in application.rb

config.autoload_paths += %W(#{config.root}/app/modules)

When I try to load up a model that calls acts_as_lockable I get the following error:

NameError: undefined local variable or
method `acts_as_lockable’

My guess is that I shouldn’t be autoloading the modules folder because ActiveRecord has already been loaded when I extend it? Is there another way to do this? I would like to be able to alter the file during development without restarting my server but that’s more of a want that a need.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:24:53+00:00Added an answer on May 23, 2026 at 2:24 am

    I think you’re thinking about this in the wrong way.

    You are adding this module to the load path,

    but it will only load if you either say;

    require 'acts_as_lockable'
    

    or

    ActsAsLockable
    

    I’d suggest you never really want to say either of these inside your code.

    The correct paradigm you’re looking for is an “initializer”.

    I suggest you create a file called “config/initializers/acts_as_lockable.rb”

    In this file you can either include the whole code,

    or just include a require 'acts_as_lockable'

    Normally I keep things like this inside the libs directory

    ensure lib is in the load path

    ** config/application.rb **

    config.autoload_paths += %W(#{config.root}/lib)
    

    ** lib/acts_as_lockable.rb **

    module ActsAsLockable
    
      def acts_as_lockable
        before_create :set_lock
    
        include InstanceMethods
      end
    
      module InstanceMethods
        protected
    
        def set_lock
          now = Time.now.to_s
          self.lock = Digest::SHA1.hexdigest(now)
        end
      end
    
    end
    

    then in the initializer

    ** config/initializers/acts_as_lockable.rb **

    require 'acts_as_lockable'
    ActiveRecord::Base.extend ActsAsLockable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several different processes and I would like them to all log to
I have several different content type nodes (videos, image galleries, stories...) that I would
We have several websites on different domains and I'd like to be able to
I have several different controls (TextBoxes, DateTimePickers, MaskedTextBoxes) on a form that I would
In my application I do have several different string resources each per locale like:
In a new piece of code I have several different classes that refer to
I have several different sites in different hosts and I use the same JS
I have several different tables in my database and I'm trying to use Sphinx
I have several different document formats coming in. I'd like to strip out all
I have several different type of Users (different classes) in my app User1 User2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.