Extending ApplicationController with actions from plugin


#1

Hi,

I am trying to create a plugin to implement Dojo (instead of prototype
enc). For this to work I need to define a action in the
ApplicationController from the plugin (I don’t want to mess with the
applicationController file). And I want to add a filter. So is there a
way to extend it?

we I try to add a method to module ActionController rails can’t find the
action. When I add a method to class ActionController::Base, rails
requires a template (but I want to render a inline string without
template).

I don’t understand what I am doing wrong here…


#2

Hi !

2005/12/6, abou ihsaan removed_email_address@domain.invalid:

I am trying to create a plugin to implement Dojo (instead of prototype
enc). For this to work I need to define a action in the
ApplicationController from the plugin (I don’t want to mess with the
applicationController file). And I want to add a filter. So is there a
way to extend it?

Take a look at the Flash Helper Plugin
https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/

ApplicationController is extended in
https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/file/trunk/init.rb

Hope that helps !


#3

I can only add methods to the application controller, can’t access them
from the browser as actions…


#4

abouihsaan wrote:

I can only add methods to the application controller, can’t access them
from the browser as actions…

@action_methods in base contains the accessable methods, these are only
the methods of Base class and the subclasses. But I think its gathered
before the plugins are loaded somehow… maybe a dev can shed some light
on this…


#5

abou ihsaan wrote:

before the plugins are loaded somehow… maybe a dev can shed some light
on this…

@action_methods is a class instance variable and gets assigned during
processing the first request for any given controller class. By that
time, your plugin should have been loaded. I suspect there’s a bug in
your code.

– stefan

http://railsexpress.de/blog


#6

abou ihsaan wrote:

http://railsexpress.de/blog
and the dojotoolkit/dojotoolkit.rb file contains

I try to call any controller with the action test like /catalog/test/
but that doesn’t work.

Sorry, my mystake. Methods from ActionController::Base are excluded
automatically. If you want an action added to each controller, you must
add it to class ApplicationController.

– stefan


#7

skaes wrote:

abou ihsaan wrote:

http://railsexpress.de/blog
and the dojotoolkit/dojotoolkit.rb file contains

I try to call any controller with the action test like /catalog/test/
but that doesn’t work.

Sorry, my mystake. Methods from ActionController::Base are excluded
automatically. If you want an action added to each controller, you must
add it to class ApplicationController.

– stefan

well thats the problem, how do I add it when extending the plugin?

ActionController::Base::ApplicationController.send(:include,
DojoToolkit::DojoHelperPlugin::DojoApplicationController) doesn’t work.
And when I add require_dependency ‘app/controllers/application’


#8

skaes wrote:

abou ihsaan wrote:

before the plugins are loaded somehow… maybe a dev can shed some light
on this…

@action_methods is a class instance variable and gets assigned during
processing the first request for any given controller class. By that
time, your plugin should have been loaded. I suspect there’s a bug in
your code.

– stefan

http://railsexpress.de/blog

Well my init.rb contains

require_dependency ‘dojotoolkit’

ActionController::Base.send(:include,
DojoToolkit::DojoHelperPlugin::ApplicationController)

and the dojotoolkit/dojotoolkit.rb file contains

module DojoToolkit #:nodoc
module DojoHelperPlugin #:nodoc
module ApplicationController
def test
render( :inline => ‘test’ )
end
end
end
end

I try to call any controller with the action test like /catalog/test/
but that doesn’t work.


#9

Check out engines @ http://rails-engines.rubyforget.org .
It allows you to override any MVC class/action from a plugin. Great
stuff.

Luke Amdor

On Tue, Dec 06, 2005 at 03:49:22PM +0100, abou ihsaan wrote:

requires a template (but I want to render a inline string without


Luke Amdor
removed_email_address@domain.invalid

/usr/bin/fortune |

“I’ve seen, I SAY, I’ve seen better heads on a mug of beer”
– Senator Claghorn


#10

Jup, really great, I use it for a project a.t.m. but it doesn’t serve
the purpose of making dojo available easily, but I have aborted the
project. Its just to much work…

luke wrote:

Check out engines @ http://rails-engines.rubyforget.org .
It allows you to override any MVC class/action from a plugin. Great
stuff.

Luke Amdor

On Tue, Dec 06, 2005 at 03:49:22PM +0100, abou ihsaan wrote:

requires a template (but I want to render a inline string without


Luke Amdor
removed_email_address@domain.invalid

/usr/bin/fortune |

“I’ve seen, I SAY, I’ve seen better heads on a mug of beer”
– Senator Claghorn