# Why are some methods of library accessible, while others are not? (by the example of restful\_authen

**URL:** <https://www.ruby-forum.com/t/why-are-some-methods-of-library-accessible-while-others-are-not-by-the-example-of-restful-authen/124578>\
**Category:** Rails\
**Created:** [December 30, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/why-are-some-methods-of-library-accessible-while-others-are-not-by-the-example-of-restful-authen/124578 "2007-12-30T15:00:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![truetype](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9e8a1a/32.png) [@truetype](https://www.ruby-forum.com/u/truetype)\
**Post date:** [December 30, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/why-are-some-methods-of-library-accessible-while-others-are-not-by-the-example-of-restful-authen/124578/1 "2007-12-30T15:00:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![truetype](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9e8a1a/32.png) [@truetype](https://www.ruby-forum.com/u/truetype)\
**Post date:** [December 30, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/why-are-some-methods-of-library-accessible-while-others-are-not-by-the-example-of-restful-authen/124578/2 "2007-12-30T15:15:30Z")

</div>

Oleg :

> ‘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.

---

<div class="post-metadata">

**Author:** ![truetype](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9e8a1a/32.png) [@truetype](https://www.ruby-forum.com/u/truetype)\
**Post date:** [December 30, 2007, 3:26pm UTC](https://www.ruby-forum.com/t/why-are-some-methods-of-library-accessible-while-others-are-not-by-the-example-of-restful-authen/124578/3 "2007-12-30T15:26:01Z")

</div>

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
