Frank Kim
2008-Mar-29 14:18 UTC
how to add custom methods to ActionController::Base, ActiveRecord::Base
I want to add custom methods to ActionController::Base, ActiveRecord::Base so that everything that extends it will have access to these methods in my Rails app. What is the best practice for doing this? I know I can create a file in lib and require it all the time but it seems like there should be a better way. For example: class ActionController::Base def controller_path self.class.controller_path end end class ActiveRecord::Base def foo_id(prefix=nil) display_id = new_record? ? "new" : id prefix ||= self.class.name.underscore prefix != :bare ? "#{prefix.to_s}_#{display_id}" : display_id end end Thanks, Frank Kim --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---