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 7839571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:28:30+00:00 2026-06-02T15:28:30+00:00

When I click on sign in link it should check for valid username and

  • 0

When I click on sign in link it should check for valid username and password and display the message on sign in partial page, which I am calling in colorbox as a popup, but I am not able to display error messages.

This is my loginController:

def login
  if request.post?
    @user = User.new(params[:user])
    user=User.authenticate(params[:username], params[:password])
    if user.nil?
    flash[:error] = 'Login unsuccessful'
        redirect_to :back
    else
        flash[:notice] = 'Login successful'
        session[:user] = user.id
        redirect_to :controller=>'users', :action => 'show',:username=>user.username
    end
  end    
end

User.rb:

def self.authenticate(username, pass)
  user = find(:first, :conditions=>["username = ?", username])
  return nil if user.nil?
  return user if User.hash_password(pass) == user.password && username == user.username
  nil
end

In my view page_sign_in.html.erb page

<%= form_for @user, :url=>{:controller=>"logins",:action=>"login"},:remote=>true,:html=>{ :onSubmit => "return checkSignupValidation()",:id=>"signin_form", :multipart=>true}  do |f| %> 

@user is giving error: undefined methodmodel_name’ for Nilclass`

  • 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-02T15:28:31+00:00Added an answer on June 2, 2026 at 3:28 pm

    Your problem is that there is no model for the login – there is none needed. You do not want to use form_for, use instead form_tag:

    <%= form_tag controller: "logins", action: "login", etc.. do %>
      <%= text_field_tag :username %>
      <%= password_field_tag :password %>
    <% end %>
    

    Then I would recommend some improvments to your controller:

    def login
      if request.post?
        user = User.authenticate(params[:username], params[:password])
        if user.nil?
            flash[:error] = 'Login unsuccessful'
            redirect_to :back #I try to avoid :back, it feels better to use a fixed path
        else
            flash[:notice] = 'Login successful'
            session[:user] = user.id
            redirect_to :controller=>'users', :action => 'show', :username=>user.username
        end
      end    
    end
    

    You do not need the @user variable, so just avoid a unneccessary database query. I do not know if it is so good to use :back, I always try to use a fixed path.

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

Sidebar

Related Questions

I click on a link from one page that does a redirect to another
I have a Page which has a Control on it with 2 textboxes (username
HI everyone 1. As user enter username and password in sign-in-form.php then values are
Just like what happens when you click Sign in with OpenID on http://twitterfeed.com/ ,
Click on this link , you will be redirected to a shopping site. On
On click a image how can another page be previewed in the same page
I want to stop click on any links until the page is loaded. Can
I have a link that a user selects, to display a paragraph, once they
I would like to open email-signup when I click on email-signup-link . Then I
I wish to include display a jsp page as an aui dialog in liferay,

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.