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]
@[email protected](: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
@[email protected](:all)
else
@[email protected](: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?
On 8/6/06, ScuzzleButt [email protected] 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 [email protected] 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
Spoke too soon. Doesn’t allow me to overload ‘find’.
Figured it out. include Enumerable in the module. Let me know if that is
enough, seems to work.
Thanks!