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

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

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