SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Tuesday, July 20, 2010

undefined method `helper_method'

Whenever we want to move the methods from model to helper, then we will use the code base.send :helper_method.So that in views we can able to use the methods.I tried for my authentication module, so that i moved some methods (current_user,logged_in ) to helper.There i found this bug, usually i coded the same one for my rails 2.2 versions.But in rails 2.3.8 it was not compatible, so it throws the error message "undefined method for :helper_method"

Previous code in rails 2.2


def self.included(base)
base.send :helper_method,:current_user,:logged_in?
end

Then after a brief searching in net, i solved the bug.

Existing one in rails 2.3.8


def self.included(base)
base.send :helper_method,:current_user,:logged_in? if base.respond_to?(:helper_method)
end

No comments :

Post a Comment