Why are some methods of library accessible, while others are not? (by the example of restful_authentication)

If you have a model 'user' generated through restful_authentication generator, then you should have an accessor

def current_user @current_user ||= ... end

inside the file authenticated_system.rb in lib folder. If you did as it is recommended and put 'include AuthenticatedSystem' in ApplicationController, then now you have an access to the method 'current_user' in any view. The same for method 'logged_in?'.

Now try doing the same for method 'login_required', which is also inside of AuthenticatedSystem module. Doesn't work. Reads "undefined local variable or method 'login_required'".

Summing up, both 'logged_in?' and 'login_required' are inside of Authenticated System module. 'logged_in?' is accessible from any view, while 'login_required' is not.

What's the difference? Thanx

Oleg :

If you have a model 'user' generated through restful_authentication generator, then you should have an accessor

def current_user @current_user ||= ... end

inside the file authenticated_system.rb in lib folder. If you did as it is recommended and put 'include AuthenticatedSystem' in ApplicationController, then now you have an access to the method 'current_user' in any view. The same for method 'logged_in?'.

Now try doing the same for method 'login_required', which is also inside of AuthenticatedSystem module. Doesn't work. Reads "undefined local variable or method 'login_required'".

Summing up, both 'logged_in?' and 'login_required' are inside of Authenticated System module. 'logged_in?' is accessible from any view, while 'login_required' is not.

What's the difference?

#current_user and #logged_in? are available as helpers in your views because of these lines :

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

The 'included' callback (called when you do "include AuthenticatedSystem") is responsible of this, thanks to ActionController::Base.helper_method method.

   -- Jean-François.

Thank you, Jean-François.

Actually, I checked application_helper.rb before I posted here. But having found blank, I was very surprised. Didn't know that helpers could be created the way you showed.

Thanks again, Happy 2008 to you and all the community, truetype