Forum: Ruby on Rails Form trying to save null values?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C2e626d51b252b0593e4b62499ae1f96?d=identicon&s=25 Ryan Bentz (Guest)
on 2007-02-22 17:51
(Received via mailing list)
Hey to the group but looks like there's some great
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
statements when attempting to save the new user, but when it tries to
said values to their respective columns in the DB the log shows
null). My code looks like this:

profile controller:
def rSignIn
    @retailUser =[:user])
        session[:user] = RetailUser.authenticate(, @
        flash[:message] = "Signup successful"
        redirect_to :controller => "browse", :action => "retailHome"
        flash[:warning] = "Signup failed"

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

sign in view:
<% form_for :user, @retailUser, :html => {:id => "retailSignInForm"},
=> { :controller => "profile", :action => "rSignIn"} do |f| %>
        <div class="signInFormLine">
            <label for="retailSignInText">Email:</label> <%=
f.text_field:email, :id => "retailSignInText", :class=> "text" %>
        <div class="signInFormLine">
            <label for="retailSignInZip">Zip code:</label> <%=
f.text_field:location, :id => "retailSignInZip", :class=> "text" %>
        <div class="signInFormLine">
            <%= button_to "Sign In", :controller => "profile", :action
"rSignIn" %>
    <% end %>

Any clue as to what I'm doing wrong?
C2e626d51b252b0593e4b62499ae1f96?d=identicon&s=25 (Guest)
on 2007-02-22 18:14
(Received via mailing list)
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

Thanks for your time!

B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2007-02-22 18:26
(Received via mailing list)
On 22-Feb-07, at 12:12 PM, wrote:

> On Feb 22, 8:47 am, "Ryan Bentz" <> 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])
>>             <label for="retailSignInText">Email:</label> <%=
>>         </div>
>>     <% 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

General Partner
The nNovation Group inc.
This topic is locked and can not be replied to.