# Form trying to save null values?

**URL:** <https://www.ruby-forum.com/t/form-trying-to-save-null-values/86484>\
**Category:** Rails\
**Created:** [February 22, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/form-trying-to-save-null-values/86484 "2007-02-22T17:51:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Bentz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8797f3/32.png) [@Ryan\_Bentz](https://www.ruby-forum.com/u/Ryan_Bentz)\
**Post date:** [February 22, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/form-trying-to-save-null-values/86484/1 "2007-02-22T17:51:17Z")

</div>

Hey there…new to the group but looks like there’s some great  
discussion  
going on throughout!

I’m working on a sign up form right now that takes just an email and zip  
code. It appears that the email and zip code make it as far as the  
SELECT  
statements when attempting to save the new user, but when it tries to  
save  
said values to their respective columns in the DB the log shows  
VALUES(null,  
null). My code looks like this:

profile controller:  
def rSignIn  
@retailUser = RetailUser.new(params[:user])  
if request.post?  
if @retailUser.save  
session[:user] = RetailUser.authenticate(@retailUser.email, @  
retailUser.location)  
flash[:message] = “Signup successful”  
redirect\_to :controller =\> “browse”, :action =\> “retailHome”  
else  
flash[:warning] = “Signup failed”  
end  
end  
end

retail user model:  
validates\_length\_of :email, :within =\> 6…65  
validates\_length\_of :location, :is =\> 5  
validates\_presence\_of :email, :location  
validates\_uniqueness\_of :email  
validates\_format\_of :email, :with =\>  
/^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i, :message =\> “Invalid email”

attr\_protected :id

attr\_accessor :email, :location

def self.authenticate(email, location)  
u = find(:first, :conditions =\> [“user[email]=?”,email])  
return nil if u.nil?  
return u  
nil  
end

sign in view:  
\<% form\_for :user, @retailUser, :html =\> {:id =\> “retailSignInForm”},  
:url  
=\> { :controller =\> “profile”, :action =\> “rSignIn”} do |f| %\>

  
Email: \<%=  
f.text\_field:email, :id =\> “retailSignInText”, :class=\> “text” %\>  

  

  
Zip code: \<%=  
f.text\_field:location, :id =\> “retailSignInZip”, :class=\> “text” %\>  

  

  
\<%= button\_to “Sign In”, :controller =\> “profile”, :action  
=\>  
“rSignIn” %\>  

  
\<% end %\>

Any clue as to what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![Ryan\_Bentz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8797f3/32.png) [@Ryan\_Bentz](https://www.ruby-forum.com/u/Ryan_Bentz)\
**Post date:** [February 22, 2007, 6:14pm UTC](https://www.ruby-forum.com/t/form-trying-to-save-null-values/86484/2 "2007-02-22T18:14:22Z")

</div>

Okay…sorry to bug y’all, but I think I just figured out. I had  
specified attr\_accessor :email, :location in my RetailUser model.  
Apparently that was screwing things up so I need to figure out why  
exactly.

Thanks for your time!

ryan

---

<div class="post-metadata">

**Author:** ![Ryan\_Bentz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8797f3/32.png) [@Ryan\_Bentz](https://www.ruby-forum.com/u/Ryan_Bentz)\
**Post date:** [February 22, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/form-trying-to-save-null-values/86484/3 "2007-02-22T18:26:24Z")

</div>

On 22-Feb-07, at 12:12 PM, removed\_email\_address@domain.invalid wrote:

> On Feb 22, 8:47 am, “Ryan Bentz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > said values to their respective columns in the DB the log shows  
> > flash[:message] = “Signup successful”  
> > validates\_presence\_of :email, :location  
> > u = find(:first, :conditions =\> [“user[email]=?”,email])  
> > Email: \<%=  
> >   
> > \<% end %\>
> > 
> > Any clue as to what I’m doing wrong?

Welcome Ryan,

If you had legitimate fields in retail\_user model, then  
attr\_accessor :email, :location would have overloading default rails  
accessors - put another way, you don’t need to create attributes -  
rails inspects the table and creates accessors for you.

++ id is protected from mass assignment, so attr\_protected isn’t  
needed for this attribute

Cheers,  
Jodi  
General Partner  
The nNovation Group inc.  
www.nnovation.ca/blog
