Very strange problem with application.rb and login_generator

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

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 :slight_smile:

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 for details!

Hmm … no :slight_smile:

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

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

On Dec 20, 2007 12:36 AM, Alexis ROBERT [email protected] 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.

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 :slight_smile: ) :

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 :