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

  • Home
  • SEARCH
  • 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 7739759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:36:08+00:00 2026-06-01T08:36:08+00:00

I am trying to manage session of users after authentication with ldap. The authentication

  • 0

I am trying to manage session of users after authentication with ldap. The authentication part works very well, but can’t seem to generate the session id. I get “undefined method `id’ for true:TrueClass” error.

Model –

def self.Authenticate(login, pass)
  user = find_by_user_id(login)
  if user
    user
  else
    return false
  end
  conn = Net::LDAP.new(
    :host => SERVER,
    :port => PORT,
    :base => BASE,
    :auth => { 
      :username => "#{login}@#{DOMAIN}",
      :password => pass,
      :method => :simple 
    }
  )
  if conn.bind
    return true
  else
    return false
  end
rescue Net::LDAP::LdapError => e
  return false
end    

Controller –

def create
  user = User.Authenticate(params[:user_id], params[:password])

  if user
    session[:user_id] = user.id
    redirect_to theapp_url, :notice => "Logged in!"
  else
    flash.now.alert = "Invalid email or password"
    render "new"
  end
end

View –

<%= form_tag sessions_path do %>
  <p>
    <%= label_tag :Username %><br />
    <%= text_field_tag :user_id, params[:user_id] %>
  </p>
  <p>
    <%= label_tag :Password %><br />
    <%= password_field_tag :password %>
  </p>
  <p class="button"><%= submit_tag "Log in" %></p>
<% end %>

The error –

NoMethodError in SessionsController#create

undefined method `id' for true:TrueClass
Rails.root: /myapp

Application Trace | Framework Trace | Full Trace
app/controllers/sessions_controller.rb:12:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"OmzCrLHR1t/xfIXNcEzy2NCGfVpEKSyI4OZfqpPEFNw=",
 "user_id"=>"admin",
 "password"=>"[FILTERED]",
 "commit"=>"Log in"}
  • 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-06-01T08:36:09+00:00Added an answer on June 1, 2026 at 8:36 am

    In the definition of User#Authenticate, it can return true. The controller’s create action has session[:user_id] = user.id, but in this case, user is true. That is why you get the error message undefined method `id’ for true:TrueClass

    Modify your Authenticate method to always return a user, or modify your controller to accept true as a user value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to manage the login session of users that navigate in my
I am trying to install VisualSVN to manage my code with other users. In
I'm trying to use couchapp to manage my CouchDB application, but it's missing a
I am trying to pass custom variables to paypal IPN. I can manage to
I've been trying to add Facebook Connect to a website, but it didn't seem
I'm trying to manually manage some geometry (spatial) columns in a rails model. When
I am trying to work out how to manage the following relationships A Store
I'm trying to figure out how to manage my event ids. Up to this
I'm trying to get Django's manage.py to run with modified settings files. I have
I'm trying to use Apache XMLRPC to manage posts at a small weblog service.

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.