Forum: Ruby on Rails External controller code

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A337c1e777ada321c283780b97c41d37?d=identicon&s=25 Otmar Tschendel (Guest)
on 2006-03-10 14:23
(Received via mailing list)
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
5b132632f47e8c7e2a83157cef4649c8?d=identicon&s=25 Agnieszka Figiel (agnessa)
on 2006-03-10 15:30
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 Figiel
573b9499030e1ccb867ef80f0ff1ac49?d=identicon&s=25 Justin Bailey (Guest)
on 2006-03-10 17:51
(Received via mailing list)
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.
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-03-10 18:02
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
This topic is locked and can not be replied to.