External controller code


#1

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


#2

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.


#3

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.


#4

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