Forum: Ruby on Rails Extending ApplicationController with actions from plugin

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.
4b4dfab0e4b63d8e9dcbd04340b4a4c9?d=identicon&s=25 Abou Ihsaan (abouihsaan)
on 2005-12-06 15:49
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....
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 francois.beausoleil (Guest)
on 2005-12-06 15:59
(Received via mailing list)
Hi !

2005/12/6, abou ihsaan <abouihsaan@advany.com>:
> 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_plug...

ApplicationController is extended in
https://opensvn.csie.org/traccgi/flash_helper_plug...

Hope that helps !
4b4dfab0e4b63d8e9dcbd04340b4a4c9?d=identicon&s=25 Abou Ihsaan (abouihsaan)
on 2005-12-06 16:17
I can only add methods to the application controller, can't access them
from the browser as actions...
4b4dfab0e4b63d8e9dcbd04340b4a4c9?d=identicon&s=25 Abou Ihsaan (abouihsaan)
on 2005-12-06 16:41
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...
E555e7c34196967444a47a96395a23ab?d=identicon&s=25 skaes (Guest)
on 2005-12-06 17:00
(Received via mailing list)
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
4b4dfab0e4b63d8e9dcbd04340b4a4c9?d=identicon&s=25 Abou Ihsaan (abouihsaan)
on 2005-12-06 17:05
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.
E555e7c34196967444a47a96395a23ab?d=identicon&s=25 skaes (Guest)
on 2005-12-06 18:05
(Received via mailing list)
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
4b4dfab0e4b63d8e9dcbd04340b4a4c9?d=identicon&s=25 Abou Ihsaan (abouihsaan)
on 2005-12-06 18:22
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'
8b6e9047a02f6756e0dcb36863463b5b?d=identicon&s=25 luke (Guest)
on 2005-12-09 21:37
(Received via mailing list)
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
luke@absoluterubbish.net

/usr/bin/fortune |

"I've seen, I SAY, I've seen better heads on a mug of beer"
		-- Senator Claghorn
4b4dfab0e4b63d8e9dcbd04340b4a4c9?d=identicon&s=25 Abou Ihsaan (abouihsaan)
on 2005-12-09 23:41
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
> luke@absoluterubbish.net
>
> /usr/bin/fortune |
>
> "I've seen, I SAY, I've seen better heads on a mug of beer"
> 		-- Senator Claghorn
This topic is locked and can not be replied to.