# DRY Scaffolds

**URL:** <https://www.ruby-forum.com/t/dry-scaffolds/101598>\
**Category:** Rails\
**Created:** [August 6, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/dry-scaffolds/101598 "2006-08-06T16:42:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScuzzleButt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@ScuzzleButt](https://www.ruby-forum.com/u/ScuzzleButt)\
**Post date:** [August 6, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/dry-scaffolds/101598/1 "2006-08-06T16:42:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ScuzzleButt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@ScuzzleButt](https://www.ruby-forum.com/u/ScuzzleButt)\
**Post date:** [August 6, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/dry-scaffolds/101598/2 "2006-08-06T22:02:23Z")

</div>

On 8/6/06, ScuzzleButt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![ScuzzleButt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@ScuzzleButt](https://www.ruby-forum.com/u/ScuzzleButt)\
**Post date:** [August 7, 2006, 12:59am UTC](https://www.ruby-forum.com/t/dry-scaffolds/101598/3 "2006-08-07T00:59:32Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![ScuzzleButt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@ScuzzleButt](https://www.ruby-forum.com/u/ScuzzleButt)\
**Post date:** [August 7, 2006, 1:17am UTC](https://www.ruby-forum.com/t/dry-scaffolds/101598/4 "2006-08-07T01:17:15Z")

</div>

Spoke too soon. Doesn’t allow me to overload ‘find’.

---

<div class="post-metadata">

**Author:** ![ScuzzleButt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@ScuzzleButt](https://www.ruby-forum.com/u/ScuzzleButt)\
**Post date:** [August 7, 2006, 1:06am UTC](https://www.ruby-forum.com/t/dry-scaffolds/101598/5 "2006-08-07T01:06:22Z")

</div>

Figured it out. include Enumerable in the module. Let me know if that is  
enough, seems to work.

Thanks!
