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.
--
Posted via http://www.ruby-forum.com/.
Use authlogic... On Jun 5, 9:58 am, Petan Cert <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://www.ruby-forum.com/.
Library methods are not accessible in view. On Fri, Jun 5, 2009 at 3:03 PM, Dmitry Polushkin <dmitry.polushkin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Use authlogic... > > On Jun 5, 9:58 am, Petan Cert <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > 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. > > -- > > Posted viahttp://www.ruby-forum.com/. > > >-- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Ransing wrote:> Library methods are not accessible in view.-- Posted via http://www.ruby-forum.com/.
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 Cert
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:
>
> 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 Ransing wrote:
> > Library methods are not accessible in view.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
Ruby on Rails Developer
http://sandip.sosblog.com
http://funonrails.wordpress.com
www.joshsoftware.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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:> 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~-- Posted via http://www.ruby-forum.com/.
On Fri, Jun 5, 2009 at 5:47 PM, Petan Cert <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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> > 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: > > 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~ > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---