11175
(-- --)
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.
Sandip
(Sandip)
3
Library methods are not accessible in view.
Sandip
(Sandip)
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~
11175
(-- --)
5
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 Ransing wrote:
Sandip
(Sandip)
6
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