"Helper" for 2 controllers?

Is there a DRY way to have a helper method for 2 different controllers?

For example:
@user.create_points_account(10)
@group.create_points_account(10)

and the helper method would look like this:

def create_points_account pts
f = PointAccount.new(:points => pts)
f.resource = self
return false if !f.save
end

Place it in a module somewhere and have both controllers to include that
module.

Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)

On Thu, Apr 23, 2009 at 4:47 PM, Heinz S.

I included it in the controller with helper :points and called it like
above but I get an error:
undefined method create_points_account

What could be the problem?

Maurício Linhares wrote:

Place it in a module somewhere and have both controllers to include that
module.

Maur�cio Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)

On Thu, Apr 23, 2009 at 4:47 PM, Heinz S.

I changed it from helper :fund to include Fund and it’s included now but
it doesn’t really help cause there’s still the error:
undefined method `create_fund’ for #User:0x5d52c6c

I guess I did not made myself clear.

I said create a module somewhere (usually under the lib folder), like:

#lib/points.rb

module Points

def create_points_account( pts )
f = PointAccount.new(:points => pts)
f.resource = self
return false if !f.save
end

end

And then at your controller:

class SomeController < ActionController::Base

include Points

end

Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)

On Thu, Apr 23, 2009 at 5:03 PM, Heinz S.