I''ve got 8 scaffolds, each one can be considered an ''item'', such as a blog, photo, etc. Using login_engine and user_engine, I list all blogs belonging to a user by saying: @user=session[:user] @blogs=@user.blogs.find(:all) but then let''s say I want to create an option where I want to slice it differently: @user=session[:user] if @someOption ==1 @blogs=@user.blogs.find(:all) else @blogs=@user.blogs.find(:all, :conditions=>["time=?",@timeOfDay]) end Having done that, now I''d like to use it in all 8 scaffolds. Right now I''m copying and pasting to each scaffold. Lame. My question is: How do I overload the ''find'' function for all 8 controllers in my 8 scaffolds, or create a new function that all 8 can access, and can distinguish which object it is receiving? -- Posted via http://www.ruby-forum.com/.
On 8/6/06, ScuzzleButt <jnkjok@joeandjody.com> wrote:> > My question is: How do I overload the ''find'' function for all 8 > controllers in my 8 scaffolds, or create a new function that all 8 can > access, and can distinguish which object it is receiving?Put it in a module under lib/ and include that module in all your scaffolds. You may need to pass in some parameter that varies with your scaffold. martin
With module myModule def someFunction #contents end end That seemed to work with instance variables, but didn''t work with Blog.someFunction Blog.find but @blog=Blog.new @blog.someFunction worked fine. In looking through the ruby docs, this would follow, but they don''t give an indication of how a class instance would work. I''ll keep browsing, but any info would be appreciated. Thanks for the help so far, it''s pointed me in a good direction. Martin DeMello wrote:> On 8/6/06, ScuzzleButt <jnkjok@joeandjody.com> wrote: >> >> My question is: How do I overload the ''find'' function for all 8 >> controllers in my 8 scaffolds, or create a new function that all 8 can >> access, and can distinguish which object it is receiving? > > Put it in a module under lib/ and include that module in all your > scaffolds. You may need to pass in some parameter that varies with > your scaffold. > > martin-- Posted via http://www.ruby-forum.com/.
Figured it out. include Enumerable in the module. Let me know if that is enough, seems to work. Thanks! -- Posted via http://www.ruby-forum.com/.