|
Subject: Re: custom methods Newsgroups: gmane.comp.lang.ruby.rails Date: 2005-05-04 16:17:22 GMT (4 years, 8 weeks, 6 days, 5 hours and 19 minutes ago) For something you need in all your models, make a file and stick it in lib. Put your functions in a module. Require it in config/environment.rb, then open up ActiveRecord::Base and include the module. Alternatevely you could just include the module directly in all of your models, but this is 1-N and could be a maintenence pain. For a method you need in all controllers, put it in app/controllers/application.rb in the ApplicationController class. For a method you need in all views, put it in app/helpers/application_helper.rb. For a method you need in all controllers and views, put it in app/controllers/application.rb and mark it with the helper_method macro. For a helper method that is relevant to only one view, put it in app/helpers/viewname_helper.rb For a helper-type method that is needed by only one controller, put it in the controller and make it non-public (If you need this, you could be inadvertently putting model code in your controller. I rarely see this case) Anything you put in lib/ can be required in config/environment.rb directly and you'll have access to it. I recommend wrapping your functions in modules to keep your namespace clean. Brian On 5/4/05, jason lynes :: senyl.com <jason@...> wrote: > where do custom methods go? i am trying to write a few methods but when i > call them, no matter where i put them, rails says they are undefined. help! > thanks- > > jason > > _______________________________________________ > Rails mailing list > Rails@... > http://lists.rubyonrails.org/mailman/listinfo/rails > > > -- The years ahead pick up their dark bags. They move closer. There's a slight rise in the silence then nothing. -- (If you're receiving this in response to mail sent to bluczkie@..., don't be concerned This is my new address, but mail will be forwarded here indefinitely) |
|
|