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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:38:58+00:00 2026-06-09T09:38:58+00:00

Hi I have a simple application, where I have created a form , using

  • 0

Hi I have a simple application, where I have created a form , using the form_for helper. On submission, when I try to access the model object in the action that’s triggered, I am not getting all the information in that correctly. Some of the attributes are coming blank. I’ve already spent a few hours on trying to debug the problem , but invain. Any help would be greatly appreciated.
Rails 3.2
Ruby 1.9.2

Code for Form is :signup.html.erb

<%= form_for (@user) , :url => { :action => "signup" ,:method=>"post"} do |u| %>
  <p>
    <%= u.label :login %>
    <%= u.text_field :login ,:size => 20 %>
  </p>
  <p>
    <%= u.label :password %>
    <%= u.text_field :password,:size => 20 %>
  </p>
  <p>
    <%= u.label :password_confirmation %>
    <%= u.text_field :password_confirmation,:size => 20 %>
  </p>
  <p>
    <%= u.label :email %>
    <%= u.text_field :email ,:size => 20 %>
  </p>
  <%= u.submit %>
<% end %>

Code for the “signup” action of user_controller.rb is

 def signup


      @user = User.new(params[:user])

       if request.post?  

        if @user.save!

          session[:user] = User.authenticate(@user.login, @user.password)
          flash[:message] = "Signup successful"
          redirect_to :action => "index"          
        else

          flash[:warning] = "Signup unsuccessful"
        end
      end

    end

When I click the submit button, I get the following error

 ActiveRecord::RecordInvalid in UserController#signup

Validation failed: Password can't be blank, Password doesn't match confirmation

Rails.root: /Users/kabir/ror/mmeter1
Application Trace | Framework Trace | Full Trace

app/controllers/user_controller.rb:42:in `signup'

Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"yTC5i0HKltD4z40f0AQhir58CF9Pz+19VnKi3lvT6aE=",
 "user"=>{"login"=>"abcde",
 "password"=>"123456",
 "password_confirmation"=>"123456",
 "email"=>"abcde@kk.com"},
 "commit"=>"Create User",
 "method"=>"post"}

The model validations for user are

  validates_presence_of :login, :email, :password, :password_confirmation, :salt
  validates_uniqueness_of :login, :email
  validates_confirmation_of :password

The source code generated for the form a just before submission is

<form accept-charset="UTF-8" action="/user/signup?method=post" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="yTC5i0HKltD4z40f0AQhir58CF9Pz+19VnKi3lvT6aE=" /></div>
  <p>
    <label for="user_login">Login</label>
    <input id="user_login" name="user[login]" size="20" type="text" />
  </p>
  <p>
    <label for="user_password">Password</label>
    <input id="user_password" name="user[password]" size="20" type="text" />
  </p>
  <p>
    <label for="user_password_confirmation">Password confirmation</label>
    <input id="user_password_confirmation" name="user[password_confirmation]" size="20" type="text" />
  </p>
  <p>
    <label for="user_email">Email</label>
    <input id="user_email" name="user[email]" size="20" type="text" />
  </p>
  <input name="commit" type="submit" value="Create User" />
</form>

I also logged the value of @user in the signup action of user_controller, and it showed the following values

The user params is {"login"=>"abcde", "password"=>"123456", "password_confirmation"=>"123456", "email"=>"abcde@kk.com"}
The user object is --- !ruby/object:User
attributes:
  id: 
  username: 
  password: 
  created_at: 
  updated_at: 
  login: abcde
  hashed_password: !binary |-
    MzFiNDk4MGRmMTU2OTEwOThhNDdkYzNjOTZhOTFjYWFiOTVkN2NiOA==
  email: abcde@kk.com
  salt: tgCV8xIfxS

Notice that the username and password fields are coming blank. Any help is appreciated.

Here’s the model code

 class User < ActiveRecord::Base
 # prevent the following fields from being updated through a post
 # request. ie, these fields cannot be updated as a result of a form
 # submittion. They can only be updated from within the model itself.
  attr_protected :id, :salt
  attr_accessible :login,:password,:password_confirmation,:email

 # set the basic validation rules for the different attributes of the user
  validates_length_of :login, :within => 3..40
 #  validates_length_of :password, :within => 5..40
  validates_presence_of :login, :email, :password, :password_confirmation, :salt
  validates_uniqueness_of :login, :email
  validates_confirmation_of :password
 #  validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "Invalid email"
  • 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-09T09:39:00+00:00Added an answer on June 9, 2026 at 9:39 am

    You did not post your entire model (it’s missing an end), are you sure you do not have additional code? The password has been stored in hashed_password and removed from the password and password_confirmation, and some method is doing that. That’s because it is unsafe to use those two fields, because they are plaintext.

    So, either in your model, or an included gem does alter the saving of a User, and that is breaking your validations.

    Maybe you used code from this page?

    http://www.napcsweb.com/blog/2010/03/11/basic-authentication-in-ruby-on-rails-in-case-you-forgot/

    And hint: in your form use password_fields instead of text_fields…

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

Sidebar

Related Questions

Ok. Here is some background: I have created a simple APEX application that is
I have created a simple blog application with Ruby on Rails. The applications consists
I have created a simple win 32 application..in which it has a textbox and
We have created a simple wix project for a basic windows application. Everything builds
I have created blank C#/XAML Windows 8 application. Add simple XAML code: <Page x:Class=Blank.MainPage
I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which
I have a requirement to create a simple windows forms application that allows an
I have simple WinForms application where modifying Windows Registry. The problem is that in
I am working on my second CI application. I have created some simple CRUD
Have created simple Ajax enabled contact forms before that have around 12 fields -

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.