External controller code

Hey,

we like to realize a RoR project with a huge amount of controller code.
What is the best way to handle that.
Is there a similar mechanism for helper as for views or a way to
include/load external code?

Otmar Tschendel

Otmar Tschendel wrote:

Hey,

we like to realize a RoR project with a huge amount of controller code.
What is the best way to handle that.
Is there a similar mechanism for helper as for views or a way to
include/load external code?

Otmar Tschendel

hi,

you could group the code in modules and then include the modules in the
controller.


Agnieszka F.

You can place non-action methods in module and save that in a file in
your
lib directory, which you can then include in your controller. Example:

lib\extra_methods.rb:
module ExtraControllerMethods

… your code

end

app\controllers\some_controller.rb:
require ‘extra_methods’
class SomeController < ApplicationController
include ExtraControllerMethods
end

A better solution, though, would be to refactor portions of your
controller
into smaller chunks. If you have so much code it’s getting unmanageable,
just splitting portions out into another file isn’t going to help much.

Otmar Tschendel wrote:

we like to realize a RoR project with a huge amount of controller code.
What is the best way to handle that.
Is there a similar mechanism for helper as for views or a way to
include/load external code?

You can put “helper” code in files in the /lib directory. You can even
make them modules and mix them in to the controller(s). Or you can split
your controller into multiple controllers and hide that division using
custom routes to map some actions to one controller and others to
another.

–josh
http://blog.hasmanythrough.com