Form Data Not Saving - probably something simple


#1

Hello. I switched to rails and mac from c# and a pc. I’m lovin it, but
wierd things keep happening with my code and after 3 days I am totally
stuck.

I have a form in login.rhtml

<%= form_tag :action => 'process_registration' %>

    <h3>Register</h3>

    <p>Email Address:<br><%= text_field "user", "email_address", :id

=> ‘stext’ %>

Password:
<%= password_field “user”, “password”, :id =>
‘stext’ %>

Confirm Password:
<%= password_field “user”,
“confirm_password”, :id => ‘stext’ %>



<%= submit_tag ‘register’ %>

<%= end_form_tag %>

this goes to my controller code:

def process_registration
@user = User.new(params[:user])
@user.save
return
end

my migration for the table:

def self.up
create_table :users do |t|
t.column :first_name, :string, :limit => 32
t.column :last_name, :string, :limit => 32
t.column :email_address, :string, :limit => 128, :null => false
t.column :password, :string, :limit => 32, :null => false
end
end

I can manually insert into the table, I can also circumvent my form and
just do a

@u = User.new
@u.email_address = “removed_email_address@domain.invalid”
@u.password = “something”
@u.save

that adds a row. if I use User.new(params[:user]) or even
@u.email_address = params[:user][:email_address] then I get nulls in the
database.

I am going insane! I have migrated down and back up, removed all
validation from my model:

class User < ActiveRecord::Base

attr_accessor :password, :email_address
attr_accessor :confirm_password

def self.authenticate( user )
find( :first, :conditions => [ “email_address = ? and password = ?”,
user[:email_address], user[:password] ] )

end

end

i have redone my form over and over, the code goes from the form to the
controller, calls the right method, etc. if I use the debugger I can see
my value in the params[:user][:password] but when save is called it only
inserts nulls.

Am I missing something really stupid?

Please help, my client is getting pissed :slight_smile:


#2

Nevermind :slight_smile: I was doing a couple of things screwy that Ruby didn’t
like. for instance I had confirm_password instead of
password_confirmation. Everything is working as expected now.