Common actions "split" amoung several controllers? how to?

Hi all -

I've got a set of common actions (for displaying photo thumbnails and their preview) that I'd like to share b/n a couple of controllers (ie. photos for people and photos for events).

I'm trying to figure out how best to extract this common functionality so it's easy to update/manage (ie. dry).

The views aren't a problem, I know how to do that, but I'm getting stuck with the controller/actions...

Right now I've got my actions in a *module* that I'm *include*'ing in each controller. Works except I get the following when one of the protected methods (defined in the module) tries to use Paginator. It works if I move it into the controller.

My module is in lib/photos.rb and the error I'm getting is this:

uninitialized constant Paginator This error occured while loading the following files:     photos/paginator.rb

Also, I'd like to setup a before_filter for these common actions, but that doesn't seem to work very well either.

Any ideas? Or other solutions?

Thanks!

-philip

(skip down)

Hi all -

I've got a set of common actions (for displaying photo thumbnails and their preview) that I'd like to share b/n a couple of controllers (ie. photos for people and photos for events).

I'm trying to figure out how best to extract this common functionality so it's easy to update/manage (ie. dry).

The views aren't a problem, I know how to do that, but I'm getting stuck with the controller/actions...

Right now I've got my actions in a *module* that I'm *include*'ing in each controller. Works except I get the following when one of the protected methods (defined in the module) tries to use Paginator. It works if I move it into the controller.

My module is in lib/photos.rb and the error I'm getting is this:

uninitialized constant Paginator This error occured while loading the following files:     photos/paginator.rb

Well, this is fixed by explicitly calling ActionController::Pagination::Paginator instead of just Paginator...

Still curious about best practices though....

Hi --

Another option is to make your own parent class (like application.rb) and have your common controllers inherit from that.

You could also play around with mixing the actions in via a module. In theory that should work but I’ve not done it.

I've got a set of common actions (for displaying photo thumbnails and their preview) that I'd like to share b/n a couple of controllers (ie. photos for people and photos for events).

I'm trying to figure out how best to extract this common functionality so it's easy to update/manage (ie. dry).

The views aren't a problem, I know how to do that, but I'm getting stuck with the controller/actions...

Right now I've got my actions in a *module* that I'm *include*'ing in each controller. Works except I get the following when one of the protected methods (defined in the module) tries to use Paginator. It works if I move it into the controller.

My module is in lib/photos.rb and the error I'm getting is this:

uninitialized constant Paginator This error occured while loading the following files:    photos/paginator.rb

Also, I'd like to setup a before_filter for these common actions, but that doesn't seem to work very well either.

Any ideas? Or other solutions?

What about putting them in application.rb? That way, they'll be in the parent class of the controller classes.

Hrm... good idea, but I think our app is too big to justify this... however, I could create another controller and have these controllers inherit from it... hrm... tempting :slight_smile:

Thanks!

-philip