[Radiant] Access to request object from within tags (answer?)

Daniel Sheppard daniels at pronto.com.au
Thu Feb 1 17:11:11 CST 2007


 
> require "app/models/page_context"
> class PageContext
>   alias initialize_before_reformhaz initialize
> 
>   def initialize(page)
>     initialize_before_reformhaz(page)
>     globals.request = page.request
>   end
> end
> 
> in my reformhaz_extansion.rb
> 
> I got
> 
> SystemStackError in SiteController#show_page
> stack level too deep
> vendor/extensions/reformhaz/reformhaz_extension.rb:29:in 
> `initialize_before_reformhaz'


The problem is the aliasing, which is happening each time your extension
is loading (so on the second load, it re-aliased your new method to
initialize_before_reformaz, so the your method ended up calling itself).

Try:

class PageContent
  unless method_defined? :__initialize_before_reformhaz
    alias initialize_before_reformhaz initialize

    def initialize(page)
      __initialize_before_reformhaz(page)
      globals.request = page.request
    end
  end
end

Dan.




More information about the Radiant mailing list