Hi, Newbie here. I would like to know where do I keep modules that I can include in the Models as well as Controllers in the app? Where do I store the modules, which files? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You can put them in the lib folder -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok If I put them in the lib folder I can include them in both models and controllers right? Any special syntax I should be aware of? And I just create a new .rb file in the lib folder and drop the module(s) in right? Sorry just confirming :) and Thanks! On Feb 5, 3:43 pm, Dermot Brennan <dermot.bren...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can put them in the lib folder-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Also, if you put 
config.autoload_paths += %W(#{config.root}/lib)
in config/application.rb, then you don''t need to use require
''cool_code''.
-- 
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hey Dermot, Thanks a Ton that did if for me :) On Feb 5, 6:47 pm, Dermot Brennan <dermot.bren...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Also, if you put > > config.autoload_paths += %W(#{config.root}/lib) > > in config/application.rb, then you don''t need to use require ''cool_code''.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.