Last active
August 29, 2015 14:02
-
-
Save hectorperez/c8c8698dfdeaf52f4b35 to your computer and use it in GitHub Desktop.
Callback in a module in Ruby on Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/7444522/is-it-possible-to-define-a-before-save-callback-in-a-module | |
class Model | |
include MyModule | |
#... | |
end | |
# lib/my_module.rb | |
module MyModule | |
extend ActiveSupport::Concern | |
included do | |
before_save :do_something | |
end | |
def do_something | |
#do whatever | |
end | |
end | |
# config/application.rb | |
module Ilitia | |
class Application < Rails::Application | |
config.autoload_paths += Dir["#{config.root}/lib"] | |
#... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment