petan
1
Hi all,
I am using rails v.2.3.2 and if I put following line to my
ApplicationController:
include LoginSystem
and I moved my login_system.rb to lib folder:
module LoginSystem
protected
def is_logged_in?
@logged_in_user = User.find(session[:user]) if session[:user]
end
def logged_in_user
return @logged_in_user if is_logged_in?
end
def logged_in_user=(user)
if !user.nil?
session[:user] = user.id
@logged_in_user = user
end
end
def self.included(base)
base.send :helper_method, :is_logged_in?, :is_admin?,
:logged_in_user
end
end
This does work under RAILS 2.1.1, but not under 2.3.2
It says: undefined method `is_logged_in?’ for
#ActionView::Base:0x78cf044
Cheers
P.
petan
2
Use authlogic…
On Jun 5, 9:58 am, Petan C. [email protected]
petan
3
Library methods are not accessible in view.
On Fri, Jun 5, 2009 at 3:03 PM, Dmitry P.
<[email protected]
wrote:
include LoginSystem
def logged_in_user
def self.included(base)
P.
Posted viahttp://www.ruby-forum.com/.
–
Ruby on Rails Developer
petan
4
Hi Petan,
instead of using is_logged_in?.
give a try for logged_in? method.
still problem then define method is_logged_in? method in
application_helper
def is_logged_in?
session[:user]
end
I hope this will work.
-Sandip R~
On Fri, Jun 5, 2009 at 3:13 PM, Petan C.
<[email protected]
wrote:
Sandip R. wrote:
Library methods are not accessible in view.
–
Posted via http://www.ruby-forum.com/.
–
Ruby on Rails Developer
petan
5
Hi Sandip,
I’ve tried to moved all the stuff from login_system.rb to
application.rb, but it is still the same.
Is there a another way to solve this trouble?
Thanks.
P.
Sandip R. wrote:
Library methods are not accessible in view.
petan
6
I moved all the stuff from my lib/login_system.rb to the
application_helper.
And I got this ubly error: NoMethodError … undefined method
`helper_method’ for #Module:0x75f19f8
So I added following line to my application_controller:
helper_method :logged_in_user, :check_administrator_role,
:check_moderator_role, :login_required, :is_logged_in?, :is_admin?
but still no luck.
Still the same error.
Cheers
P.
Sandip R. wrote:
Hi Petan,
instead of using is_logged_in?.
give a try for logged_in? method.
still problem then define method is_logged_in? method in
application_helper
def is_logged_in?
session[:user]
end
I hope this will work.
-Sandip R~
petan
7
On Fri, Jun 5, 2009 at 5:47 PM, Petan C.
<[email protected]
wrote:
I moved all the stuff from my lib/login_system.rb to the
application_helper.
Dont’ do this keep your lib/login_system.rb as it is.
restart server
lib methods are accessible in controller, only problem with views.
If you wanted to access them in view
add following line in your application controller
helper_method :method_name
Still the same error.
–
Posted via http://www.ruby-forum.com/.
–
Ruby on Rails Developer