# Very strange problem with application.rb and login\_generator

**URL:** <https://www.ruby-forum.com/t/very-strange-problem-with-application-rb-and-login-generator/123648>\
**Category:** Rails\
**Created:** [December 19, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/very-strange-problem-with-application-rb-and-login-generator/123648 "2007-12-19T14:41:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://www.ruby-forum.com/u/Alexis_ROBERT)\
**Post date:** [December 19, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/very-strange-problem-with-application-rb-and-login-generator/123648/1 "2007-12-19T14:41:17Z")

</div>

Hi,

I’m working on a very simple project, and I need to add  
authentification (I choose login\_generator). So, i’ve added the  
required things in application.rb, the require\_dependency and the  
include stuff. In the controller which requires auth, I’ve added  
before\_filter :login\_required. Exactly what they say in the  
documentation.

The problem is that I get “undefined method `login\_required’ for  
#DrugsController:0x11345ec”.

If I define a function named “test” in application.rb and if I call it  
from drugs\_controller.rb, I get the same message.

Tell me if I’m wrong, but the controllers normally inherits from  
ApplicationController defined in application.rb, no ? Why the  
functions are not accessible even if they are protected or public ?

Btw, i’m using Rails 2.0.1.

Thanks in advance

Alexis ROBERT

---

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://www.ruby-forum.com/u/Alexis_ROBERT)\
**Post date:** [December 19, 2007, 2:47pm UTC](https://www.ruby-forum.com/t/very-strange-problem-with-application-rb-and-login-generator/123648/2 "2007-12-19T14:47:50Z")

</div>

Hi –

On Wed, 19 Dec 2007, Alexis ROBERT wrote:

> The problem is that I get "undefined method `login\_required’ for
> 
> Thanks in advance

This is just a guess, but did you put the login\_required method after  
the ‘end’ line of the controller class? If so, move it up 🙂

David

–  
Training for 2008!  
Ruby on Rails training by David A. Black/Ruby Power and Light, LLC:  
\* Intro to Rails, New York, NY, February 4-7 2008  
\* Advancing With Rails, New York, NY, February 11-14 2008  
Hosted by Exceed Education. See [http://www.rubypal.com](http://www.rubypal.com) for details!

---

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://www.ruby-forum.com/u/Alexis_ROBERT)\
**Post date:** [December 19, 2007, 3:07pm UTC](https://www.ruby-forum.com/t/very-strange-problem-with-application-rb-and-login-generator/123648/3 "2007-12-19T15:07:51Z")

</div>

Hmm … no 🙂

That’s the code :

– drugs\_controller.rb –  
class DrugsController \< ApplicationController  
layout “standard”  
before\_filter :login\_required

[snip]  
end

– application.rb –  
require\_dependency “login\_system”

class ApplicationController \< ActionController::Base  
include LoginSystem  
helper :all # include all helpers, all the time

[protect\_from\_forgery stuff]  
end

Alexis

---

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://www.ruby-forum.com/u/Alexis_ROBERT)\
**Post date:** [December 20, 2007, 12:07am UTC](https://www.ruby-forum.com/t/very-strange-problem-with-application-rb-and-login-generator/123648/4 "2007-12-20T00:07:57Z")

</div>

LoginSystem is old and possibly not maintained any more. I think it’s  
been  
superseded by AuthenticatedSystem (acts\_as\_authenticated) and the  
methods  
used in both modules are very similar. I recommend upgrading to  
acts\_as\_authenticated  
[http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated](http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated)

On Dec 20, 2007 12:36 AM, Alexis ROBERT [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [snip]  
> end
> 
> > > #DrugsController:0x11345ec".  
> > > Thanks in advance  
> > > \* Advancing With Rails, New York, NY, February 11-14 2008  
> > > Hosted by Exceed Education. Seehttp://www.rubypal.comfor details!

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://www.ruby-forum.com/u/Alexis_ROBERT)\
**Post date:** [December 21, 2007, 6:51pm UTC](https://www.ruby-forum.com/t/very-strange-problem-with-application-rb-and-login-generator/123648/5 "2007-12-21T18:51:55Z")

</div>

Thanks a lot !

But, by the way, the main problem is still here (and so, if i want to  
put authentification, i need to copy/paste the include line, which is  
not very clean 🙂 ) :

For example, this code raises an “undefined method `blah’ for  
#DrugsController:0x17d60bc” :

– drugs\_controller.rb –  
class DrugsController \< ApplicationController  
def index  
self.blah()  
end  
end

– application.rb –  
class ApplicationController \< ActionController::Base  
helper :all # include all helpers, all the time

def blah  
return 2  
end  
end

If I put “print self.blah” before self.blah(), i get a “nil”. So the  
method is not inherited (even if i put it protected). I don’t  
understand how can it could be (unless that the  
“ApplicationController” in drugs\_controller.rb is not the same as the  
application.rb’s one, but that’s pretty weird).

Alexis

Le 20 dÃ©c. 07 Ã 00:07, Ryan B. a Ã©crit :
