Form trying to save null values?

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| %>

    <div class="signInFormLine">
        <label for="retailSignInText">Email:</label> <%= f.text_field :email, :id => "retailSignInText", :class=> "text" %>

    </div>
    <div class="signInFormLine">
        <label for="retailSignInZip">Zip code:</label> <%= f.text_field :location, :id => "retailSignInZip", :class=> "text" %>

    </div>
    <div class="signInFormLine">
        <%= button_to "Sign In", :controller => "profile", :action => "rSignIn" %>
    </div>

<% end %>

Any clue as to what I’m doing wrong?

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

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

on-innovation.gif