On Apr 8, 7:42 pm, Alex Shulgin <[email protected]> wrote:
> On Apr 8, 5:06 pm, Frederick Cheung <[email protected]>
> wrote:
>
>
>
> > Because you're in development mode, the app's code, including
> > application_helper is reloaded for each request, but your plugin's
> > init.rb is only called once and never gets to do your monkey patching
> > on the reloaded copies of application helper
>
> > You might be able to use a to_prepare callback (these get called
> > before each request in development mode) if you're going to use this a
> > lot in development mode - take a peek inside action_dispatch/
> > middleware/callbacks
>
> Yes, but I *was* using a to_prepare block (w/o actually understanding
> what it does, though.)
>
> So what I now actually have in init.rb is this:
>
> Dispatcher.to_prepare :redmine_model_dependencies do
>   puts "!!! to_prepare block !!!"
>
>   require_dependency 'application_helper'
>
>   unless ApplicationHelper.included_modules.include?
> RedminePastebin::ApplicationHelperPatch
>     ApplicationHelper.send(:include,
> RedminePastebin::ApplicationHelperPatch)
>   end
> end

Now, that's interesting.  The above method supposed to work, and it
does work with, e.g. users_helper (see
http://www.redmine.org/projects/redmine/wiki/Plugin_Internals#Wrapping-an-existing-method
for the supported way of overriding helper methods.)

But this does not work with application_helper.  I come to think it is
special in some way.

If I put this into my init.rb:

Dispatcher.to_prepare :redmine_model_dependencies do
  require_dependency 'users_helper'
  require_dependency 'application_helper'

  unless UsersHelper.included_modules.include?(LockUsersHelperPatch)
    puts "!!! UsersHelper !!!"
    UsersHelper.send(:include, LockUsersHelperPatch)
  end

  unless ApplicationHelper.included_modules.include?
ApplicationHelperPatch
    puts "!!! ApplicationHelper !!!"
    ApplicationHelper.send(:include, ApplicationHelperPatch)
  end
end

I can clearly see that UserHelperPatch is included on every page load,
while ApplicationHelperPatch is only included for the first time.  So
it somehow thinks it is included, but calls the wrong (unaliased)
method.

Any help on this is greatly appreciated!

--
Alex

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to