Adding page-specific Javascript to each view in CakePHP

In an attempt to keep my scripts maintainable, I'm going to move each into their own file, organised by controller and action:

// scripts which only apply to /views/posts/add.ctp

// scripts which only apply to /view/users/index.ctp

That's all cool, however I'd like for these to be automatically added by the Controller, since it obviously knows the name of both the controller and action.

I figure the best place for this is in AppController::beforeRender(). (yes?)

The only problem is that I don't know how to actually add this into the $scripts_for_layout variable. I thought that getting a reference to the javascript helper object would work, but I can't find it from the controller!

class AppController extends Controller {
    var $helpers = array("javascript", "html", "form");

    function beforeRender() {
        // ???