Project

General

Profile

Redefine helper

Added by Stefano Stefano almost 14 years ago

I just created a plugin to redefine html_title in application helper and I puts file under /vendors/<my_plugin>/apps/helpers/application_helper.rb. When I try to load page for first time title respect my changes, then when I refresh other pages it is printed using original method.

module ApplicationHelper
    # Redefine page title
    def html_title(*args)
        if args.empty?
            title = ['Project']
            title += @html_title if @html_title
            title.select {|t| !t.blank? }.join(' :: ')
        else
            @html_title ||= []
            @html_title += args
        end
    end

    # Add clearfix div tag
    def clearfix_tag()
        content_tag(:div, "", :class=>"clearfix")
    end
end


Replies (6)

RE: Redefine helper - Added by Felix Schäfer almost 14 years ago

Mmh, tough one because you can't add to modules after their creation, you can only import another module afterwards to overwrite methods from the original module. Try renaming your helper to something else and inject it into ApplicationController, that should overwrite #html_title from the original ApplicationHelper for all Controllers derived from it.

Anyway, that's all theory because I've never tried something like that… Try asking on the rails mailing list as this is rather a general ruby/rails problem than a redmine one.

RE: Redefine helper - Added by Stefano Stefano almost 14 years ago

Thanks for your answer. I just follow this guide: http://www.redmine.org/projects/redmine/wiki/Plugin_Internals#Overriding-the-Redmine-Core
I get always same behavior. My changes are apply only the first time

RE: Redefine helper - Added by Felix Schäfer almost 14 years ago

Mmh, I'm sorry, I don't know enough of ruby stuff so advanced, you could try to ask edavis10 on IRC.

RE: Redefine helper - Added by Bogdan Vlad over 13 years ago

I'm having a similar problem. I've created a new method in application_helper which lists on all my pages the projects list. I installed the wiki extensions plugin and now the list of projects is available on all the pages except the wiki page. I'm stuck :( Can anyone point me to what I'm doing wrong?

RE: Redefine helper - Added by Alex Shulgin over 13 years ago

Hey, I'm also being hit by this problem!

I've started a discussion here: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/dde7d7fa30cc698d since my first thought was that it's not redmine-specific.

I've used a lot of tricks trying to make it work, but it seems that it only works for helpers other than ApplicationHelper. It must be specific in some way...

--
Alex

RE: Redefine helper - Added by Bogdan Vlad over 13 years ago

I don't know if my solution is ok but it works for me. What I did was to include the patch in the ActionView class. Now the method is used through the entire site.

    (1-6/6)