Forum: Ruby on Rails rails 2.3.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
97bd2f0974055dacf53a0643b013b32e?d=identicon&s=25 Petan Cert (petan)
on 2009-06-05 10:58
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.
832ed6ace46d61032151f4e1864c057f?d=identicon&s=25 Dmitry Polushkin (polushkind)
on 2009-06-05 11:35
(Received via mailing list)
Use authlogic...

On Jun 5, 9:58 am, Petan Cert <rails-mailing-l...@andreas-s.net>
4ab2692ba129cb296d4f2e90ba5241da?d=identicon&s=25 Sandip Ransing (san2821)
on 2009-06-05 11:40
(Received via mailing list)
Library methods are not accessible in view.

On Fri, Jun 5, 2009 at 3:03 PM, Dmitry Polushkin
<dmitry.polushkin@gmail.com
> wrote:

> > include LoginSystem
> >   def logged_in_user
> >   def self.included(base)
> > P.
> > --
> > Posted viahttp://www.ruby-forum.com/.
> >
>


--
Ruby on Rails Developer
http://sandip.sosblog.com
http://funonrails.wordpress.com
www.joshsoftware.com
97bd2f0974055dacf53a0643b013b32e?d=identicon&s=25 Petan Cert (petan)
on 2009-06-05 11:43
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.
4ab2692ba129cb296d4f2e90ba5241da?d=identicon&s=25 Sandip Ransing (san2821)
on 2009-06-05 12:17
(Received via mailing list)
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@andreas-s.net
> wrote:

>
>
> 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
97bd2f0974055dacf53a0643b013b32e?d=identicon&s=25 Petan Cert (petan)
on 2009-06-05 14:17
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~
4ab2692ba129cb296d4f2e90ba5241da?d=identicon&s=25 Sandip Ransing (san2821)
on 2009-06-05 17:08
(Received via mailing list)
On Fri, Jun 5, 2009 at 5:47 PM, Petan Cert
<rails-mailing-list@andreas-s.net
> 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
http://sandip.sosblog.com
http://funonrails.wordpress.com
www.joshsoftware.com
This topic is locked and can not be replied to.