Miriam,
Name your user object in both the new and create actions to @user.
You''re looking for errors on the @user instance variable , but
you''re
creating a @newuser instance variable in your action.
Hope this helps.
Cody
On 11/30/05, Miriam P. Raphael
<miriamraphael-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>
wrote:> I can''t figure out why my validation errors are not showing up
when I submit
> my form with errors.
> My new.rhtml view looks like:
>
> <% unless @user.errors.empty? %>
> <p>Your comment could not be saved because:</p>
> <ul>
> <% @user.errors.each_full do |msg| %>
> <li><%= msg %></li>
> <% end %>
> </ul>
> <% end %>
> <form action="/user/create" method="post">
> <table width=400>
> <tr bgcolor="#999999"><td colspan=2>Please choose a
username and password to
> create your account</tr>
> <tr><td>Us er Name*:</td><td><input
id="username" name="user[username]"
> maxlength=12 type=text></tr>
> <tr><td>Password*:</td><td><input
id="password"
> name="user[password]" maxlength=12 type=password></tr>
> <tr bgcolor="#999999"><td colspan=2>Account
Information</td></tr>
> <tr><td>Company Name*:</td><td><input
id="company_name"
> name="user[company_name]" maxlength=25
type=text></td></tr>
> <tr><td>First Name*:</td><td><input
id="first_name" name="user[first_name]"
> maxlength=25 type=text></td></tr>
> <tr><td>Last Name*:</td><td><input
id="last_name" name="user[last_name]"
> maxlength=25 type=text></td></tr>
> <tr><td>Email Address*:</td><td><input
id="email" name="user[email]"
> maxlength=35 type=text></td></tr>
> <tr><td>Address 1*:</td><td><input
id="address1" name="user[address1]"
> maxlength=40 type=text></td></tr>
> <tr><td>Address 2:</td><td><input
id="address2" name="user[address2]"
> maxlength=40 type=text></td></tr>
> <tr><td>City*:</td><td><input
id="city" name="user[city]" maxlength=35
> type=text></td></tr>
> <tr><td>State:</td>
> <td><select name="user[state]">
> <% @mystates.each do |state| %>
> <option value="<%= state.statename %>">
> <%= state.statename %>
> </option>
> <% end %>
> </select>
> </td></tr>
> <tr><td>Zip Code*:</td><td><input
id="zip" name="user[zip]" maxlength=12
> type=text></td></tr>
> <tr><td>Phone*:</td><td><input
id="phone" name="user[phone]" maxlength=15
> type=text></td></tr>
> <tr><td>Mobile*:</td><td><input
id="mobile" name="user[mobile]" maxlength=15
> type=text></td></tr>
> <tr><td colspan=2><input type="submit" value=
"Save and Continue"></td></tr>
> </form>
> </table>
>
> My Model looks like:
>
> validates_length_of :username, :within =>6..12,
:message=>"Username must be
> at least 10 characters"
> validates_presence_of :username, :password, :company_name, :first_name,
> :last_name, :email, :address1, :address2, :city, :zip, :phone
> validates_uniqueness_of :username
>
> And my controller looks like:
>
> class UserController < ApplicationController
> ActiveRecord::Validations::ClassMethods
> scaffold :user
>
> def new
> @user = User.new
> @mystates = State.find_all
> @user.errors
> end
> def create
> @newuser = User.new(@params[''user''])
> @newuser.creation_date = Date.today
> @newuser.last_login = Date.today
> if @newuser.save
> flash[:notice] = "Entry was successfully created"
> redirect_to :action => "new"
> else
> render_action "new"
> end
> end
> end
>
> I also tried inserting "<%= error_messages_for
''user'' %>" into my view, but
> that didn''t work either. What''s happening now is if i
submit the form with
> an ''errors'', the new view/template reappears without any
errors. I want it
> to reappear with errors (and also preferably wit h the user''s info
defaulted
> so that they don''t have to retype it in).
> I''ve already spent two hours trying to get this to work :( Any
help will be
> much appreciated!
>
>
> ________________________________
> Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
--
http://www.codyfauser.com