No special syntax.
Just 'require' to load the module to make the application aware of that
code's existence. Then include to add the methods of that module to either
the model or controller.
# lib/cool_code.rb
module CoolCode
def do_stuff
Rails.logger.debug "do stuff"
end
end
# app/controllers/welcome_controller.rb
require 'cool_code'
class WelcomeController < ApplicationController
include CoolCode
def index
do_stuff
end
end
# app/models/post.rb
require 'cool_code'
class Post < ActiveRecord::Base
include CoolCode
def some_method
do_stuff
end
end
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.