abou ihsaan
2005-Dec-06 14:49 UTC
Extending ApplicationController with actions from plugin
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.... -- Posted via http://www.ruby-forum.com/.
Francois Beausoleil
2005-Dec-06 14:55 UTC
Re: Extending ApplicationController with actions from plugin
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_plugin/trac.cgi/ ApplicationController is extended in https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/file/trunk/init.rb Hope that helps ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
abou ihsaan
2005-Dec-06 15:17 UTC
Re: Extending ApplicationController with actions from plugin
I can only add methods to the application controller, can''t access them from the browser as actions... -- Posted via http://www.ruby-forum.com/.
abou ihsaan
2005-Dec-06 15:29 UTC
Re: Extending ApplicationController with actions from plugin
abouihsaan wrote:> I can only add methods to the application controller, can''t access them > from the browser as actions...There must be a variable that "contains" the available actions... -- Posted via http://www.ruby-forum.com/.
abou ihsaan
2005-Dec-06 15:41 UTC
Re: Extending ApplicationController with actions from plugin
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... -- Posted via http://www.ruby-forum.com/.
Stefan Kaes
2005-Dec-06 15:59 UTC
Re: Re: Extending ApplicationController with actions from plugin
abou ihsaan wrote:>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... > > >@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
abou ihsaan
2005-Dec-06 16:05 UTC
Re: Re: Extending ApplicationController with actions from pl
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/blogWell 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. -- Posted via http://www.ruby-forum.com/.
Stefan Kaes
2005-Dec-06 17:03 UTC
Re: Re: Re: Extending ApplicationController with actions from pl
abou ihsaan wrote:>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. > > >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
abou ihsaan
2005-Dec-06 17:21 UTC
Re: Re: Re: Extending ApplicationController with actions fro
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. > > -- stefanwell 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'' -- Posted via http://www.ruby-forum.com/.
abou ihsaan
2005-Dec-06 17:22 UTC
Re: Re: Re: Extending ApplicationController with actions fro
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. > > -- stefanwell 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'' -- Posted via http://www.ruby-forum.com/.
Stefan Kaes
2005-Dec-06 17:29 UTC
Re: Re: Re: Re: Extending ApplicationController with actions fro
abou ihsaan wrote:>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'' > > >Something seems to be missing from your mail. Anyway, this can''t work, as the class is just ApplicationController, not ActionController::Base::ApplicationController. But even if you change this, it won''t work, due to way classes are reloaded. Why do you need such a feature? -- stefan
abou ihsaan
2005-Dec-06 18:01 UTC
Re: Re: Re: Re: Extending ApplicationController with actions
skaes wrote:> abou ihsaan wrote: > >>>>and the dojotoolkit/dojotoolkit.rb file contains >>>add it to class ApplicationController. >> >> >> > Something seems to be missing from your mail. > > Anyway, this can''t work, as the class is just ApplicationController, not > ActionController::Base::ApplicationController. But even if you change > this, it won''t work, due to way classes are reloaded. > > Why do you need such a feature? > > -- stefanyeh sorry, some of part of my mail broke I think, but I want dojo to include a file with the generated javascript code (seperate javascript/html/css). The javascript code is genereated when the page is completely parsed (helpers like link_to_remote generate javascript that is added to flash[''dojo_file'']). I output the javascript when a action is called. And I replace the <dojo input tag> (I output this tag with javascript_include_tag) with a filter. Both methods need to be called by assigned to all controllers... a.t.m I have implemented it by adding the actions to application.rb, but I want to make the integration of dojo very easy. -- Posted via http://www.ruby-forum.com/.
abou ihsaan
2005-Dec-06 19:09 UTC
Re: Re: Re: Re: Extending ApplicationController with actions
If anyone knows a other sollution beside defining own methods in Application Controller I would be really happy. Because this kind of sucks : ) -- Posted via http://www.ruby-forum.com/.
Julian ''Julik'' Tarkhanov
2005-Dec-06 20:10 UTC
Re: Re: Re: Re: Re: Extending ApplicationController with actions
On 6-dec-2005, at 20:09, abou ihsaan wrote:> If anyone knows a other sollution beside defining own methods in > Application Controller I would be really happy. Because this kind of > sucks : )Look how the Scaffolding module is built. -- Julian ''Julik'' Tarkhanov me at julik.nl
Trevor Squires
2005-Dec-06 20:12 UTC
Re: Re: Re: Re: Re: Extending ApplicationController with actions
Well, I''m not terribly clear on what you''re trying to achieve. If I hear you say "I have a bunch of canned actions that I want to ship as a library and I want all controllers to have those actions" then I''d say do this: in my_canned_actions.rb module MyCannedActions def action_one # stuff here end def action_two # stuff here end end Then you instruct people who want to use your library to do this: in application_controller.rb require_dependency ''my_canned_actions'' class ApplicationController < ActionController::Base include MyCannedActions end If your my_canned_actions.rb file is shipped in a plugin then your init.rb file can take care of the require for them so it wouldn''t be needed. The reason you can''t ''send'' the include to ApplicationController in your plugin''s init.rb file is because your ''send'' is only evaluated once (which is a *good* thing, trust me) while, at least in development mode, the controllers/application.rb file is evaluated for each request. One final thing, and this is just my personal preference, but I would be uncomfortable using a plugin that defined controller actions for me. Actions are entry points into my application so I want to have complete control over them for reasons of security and extensibility. If that means some extra typing and/or integration work to use a 3rd party library then so be it. It''s my responsibility as the application author. (self.preach_mode = :off) HTH, Trevor On 6-Dec-05, at 11:09 AM, abou ihsaan wrote:> If anyone knows a other sollution beside defining own methods in > Application Controller I would be really happy. Because this kind of > sucks : ) > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsTrevor Squires http://somethinglearned.com
Luke Amdor
2005-Dec-09 20:34 UTC
Re: Extending ApplicationController with actions from plugin
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:> 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.... > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Luke Amdor luke-Hk3lrmVzaNfBeN7rVTv1SdHuzzzSOjJt@public.gmane.org /usr/bin/fortune | "I''ve seen, I SAY, I''ve seen better heads on a mug of beer" -- Senator Claghorn
abou ihsaan
2005-Dec-09 22:41 UTC
Re: Extending ApplicationController with actions from plugin
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-Hk3lrmVzaNfBeN7rVTv1SdHuzzzSOjJt@public.gmane.org > > /usr/bin/fortune | > > "I''ve seen, I SAY, I''ve seen better heads on a mug of beer" > -- Senator Claghorn-- Posted via http://www.ruby-forum.com/.