Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 908253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:41:11+00:00 2026-05-15T16:41:11+00:00

I have defined a function called is_logged_in? in a user defined library stored in

  • 0

I have defined a function called is_logged_in? in a user defined library stored in the /lib directory, however when I try to use it in one of my views (in this case a _menu.html.erb view) I get a “undefined method `is_logged_in?’ for #” error. I had assumed that if the method was available within the /lib directory then it would be accessible through the application?

my login_system.rb file is as follows:

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, :logged_in_user
  end
end

and my _menu.html.erb file is as follows:

<ul>
 <li><%= link_to 'Home', '/' %></li>
 <li><%= link_to 'Edit Page', pages_path %></li>

 <li><hr size = "1" width = "90%" aligh = "left" /></li>

 <% if is_logged_in? %>
  <li> Logged in as: <i><%= logged_in_user.username%> </i></li>
  <li><%= link_to 'Logout',{:controller => 'account', :action => 'logout'}, :method => :post%> </li>
 <% else %>
  <li><%= link_to 'Signup', :controller => 'users', :action => 'new' %> </li>
  <li><%= link_to 'Login', :controller => 'account', :action => 'login' %></li>
 <% end %>
</ul>

Can anyone point where I’ve gone wrong?

Bernard

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:41:11+00:00Added an answer on May 15, 2026 at 4:41 pm

    edit your ApplicationController:

    class ApplicationController < ActionController::Base
      include 'login_system'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function, where if a variable is not defined, exit; is called,
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have a User Defined Function (UDF) written in Java to parse lines in
Most systems will have a user-defined function (UDF) available. Some will not. i want
Assume you have a programme with multiple functions defined. Each function is called in
I have defined two classes in javascript as follows. function ParentClass(){ this.one = function(){
I have defined a function called login that should return a token. The token
I have a function defined in jquery closure and called by another function in
I have defined a function called once as follows: once <- function(x, value) {
I have defined a function in vim to properly indent folds. Ie so they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.