diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-06-09 09:19:15 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-06-09 09:19:15 +0000 |
commit | d21bacb01de0f4ebbac72dfb98c541d7ba9401ac (patch) | |
tree | 0b3011b8b79ab91695e697361762fd6b54d89294 /lib | |
parent | 8b381e3bd4ec47091dafa480fd34eba761a25f19 (diff) | |
download | redmine-d21bacb01de0f4ebbac72dfb98c541d7ba9401ac.tar.gz redmine-d21bacb01de0f4ebbac72dfb98c541d7ba9401ac.zip |
Fixed that content_for does not work in Hook.render_on (#11105).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9785 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/hook.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/redmine/hook.rb b/lib/redmine/hook.rb index 83c9816b2..c8f483949 100644 --- a/lib/redmine/hook.rb +++ b/lib/redmine/hook.rb @@ -107,7 +107,13 @@ module Redmine # def self.render_on(hook, options={}) define_method hook do |context| - context[:controller].send(:render_to_string, {:locals => context}.merge(options)) + if context[:hook_caller].respond_to?(:render) + context[:hook_caller].send(:render, {:locals => context}.merge(options)) + elsif context[:controller].is_a?(ActionController::Base) + context[:controller].send(:render_to_string, {:locals => context}.merge(options)) + else + raise "Cannot render #{self.name} hook from #{context[:hook_caller].class.name}" + end end end @@ -138,14 +144,15 @@ module Redmine # * project => current project # * request => Request instance # * controller => current Controller instance + # * hook_caller => object that called the hook # module Helper def call_hook(hook, context={}) if is_a?(ActionController::Base) - default_context = {:controller => self, :project => @project, :request => request} + default_context = {:controller => self, :project => @project, :request => request, :hook_caller => self} Redmine::Hook.call_hook(hook, default_context.merge(context)) else - default_context = { :project => @project } + default_context = { :project => @project, :hook_caller => self } default_context[:controller] = controller if respond_to?(:controller) default_context[:request] = request if respond_to?(:request) Redmine::Hook.call_hook(hook, default_context.merge(context)).join(' ').html_safe |