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

**URL:** <https://discuss.rubyonrails.org/t/very-strange-problem-with-application-rb-and-login-generator/21973>\
**Category:** rubyonrails-talk\
**Created:** [December 19, 2007, 1:41pm UTC](https://discuss.rubyonrails.org/t/very-strange-problem-with-application-rb-and-login-generator/21973 "2007-12-19T13:41:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://discuss.rubyonrails.org/u/Alexis_ROBERT)\
**Post date:** [December 19, 2007, 1:41pm UTC](https://discuss.rubyonrails.org/t/very-strange-problem-with-application-rb-and-login-generator/21973/1 "2007-12-19T13:41:02Z")

</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:** ![David\_A\_Black](https://avatars.discourse-cdn.com/v4/letter/d/dbc845/32.png) [@David\_A\_Black](https://discuss.rubyonrails.org/u/David_A_Black)\
**Post date:** [December 19, 2007, 1:47pm UTC](https://discuss.rubyonrails.org/t/very-strange-problem-with-application-rb-and-login-generator/21973/2 "2007-12-19T13:47:12Z")

</div>

Hi --

---

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://discuss.rubyonrails.org/u/Alexis_ROBERT)\
**Post date:** [December 19, 2007, 2:06pm UTC](https://discuss.rubyonrails.org/t/very-strange-problem-with-application-rb-and-login-generator/21973/3 "2007-12-19T14:06:59Z")

</div>

Hmm ... no 🙂

That's the code :

-- drugs\_controller.rb -- class DrugsController \< ApplicationController &nbsp;&nbsp;layout "standard" &nbsp;&nbsp;before\_filter :login\_required

&nbsp;&nbsp;[snip] end

-- application.rb -- require\_dependency "login\_system"

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

&nbsp;&nbsp;[protect\_from\_forgery stuff] end

Alexis

---

<div class="post-metadata">

**Author:** ![Alexis\_ROBERT](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@Alexis\_ROBERT](https://discuss.rubyonrails.org/u/Alexis_ROBERT)\
**Post date:** [December 21, 2007, 5:50pm UTC](https://discuss.rubyonrails.org/t/very-strange-problem-with-application-rb-and-login-generator/21973/4 "2007-12-21T17:50:52Z")

</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
