[Radiant] Access to dummy ActionController?
Daniel Sheppard
daniels at pronto.com.au
Tue Jul 4 18:22:59 CDT 2006
>From a behavior's process method, you've got access the same request and
response objects that and ActionController wants so you can pretty much
delegate completely to a controller:
class MyController < ApplicationController
def initialize(behavior)
@behavior = behavior
end
def some_action
render :text => "My behavior says that my url is
#{@behavior.page_url}"
end
end
class MyBehavior < Behavior::Base
def process(request, response)
MyController.new(self).process(request, response, :some_action)
end
end
I'm doing this for the moment with my Commentable behavior, and it seems
to work, but haven't tested it fully yet.
Most of the functionality of a controller is provided by modules, so you
should be able to get most of what you want by including the various
ActionController modules.
> -----Original Message-----
> From: radiant-bounces at lists.radiantcms.org
> [mailto:radiant-bounces at lists.radiantcms.org] On Behalf Of Jay Levitt
> Sent: Wednesday, 5 July 2006 7:54 AM
> To: radiant at lists.radiantcms.org
> Subject: [Radiant] Access to dummy ActionController?
>
> It would really be nice to have access to ActionController
> methods from
> within a behavior. F'rinstance, I wrote a behavior to
> generate Google
> sitemaps (which I'll share when it, uh, works), but I have no way to
> know the proper URL for the site without url_for.
>
> Apparently they have a similar problem in ActionMailer right
> now, and a
> workaround goes like this, per a post from Pete Yandell to rails-core:
>
> > This is the code I currently use to solve this problem. In a
> > before_filter I do UrlGenerator.controller = self, and then I can
> > call UrlGenerator.url_for from my mailer to generate URLs.
> (I pinched
> > this idea from an open source Rails project somewhere, but I don't
> > recall where. My apologies to the original author.)
> >
> > class UrlGenerator
> > @@controller ||= nil
> >
> > def self.controller=(controller)
> > @@controller = controller
> > end
> >
> > def self.url_for(options)
> > @@controller.url_for(options) if @@controller
> > end
> > end
>
> Any chance SiteController could do this for us?
>
> Jay Levitt
>
> _______________________________________________
> Radiant mailing list
> Radiant at lists.radiantcms.org
> http://lists.radiantcms.org/mailman/listinfo/radiant
>
More information about the Radiant
mailing list