rails 3.0.9 usability problem

If there is an error with the submitted password on a form, then both the password and password confirmation text fields should be highlighted in red. The default seems to be to highlight only the password field.

Any suggestions on how to correct that? Because rails magically handles the highlighting, I'm not sure how to intercept that.

I can get some code to work in the view, but it makes the view pretty messy:

views/users/new.htmt.erb:

<h1>Sign up</h1>

<%= form_for(@user) do |f| %>   <%= render 'shared/error_messages' %>

  <div class="field">     <%= f.label :name, "Name:"%>   </div>   <div>     <%= f.text_field :name %>   </div>

  <div class="field">     <%= f.label :email, "Email:" %>   </div>   <div>     <%= f.text_field :email %>   </div>

  <div class="field">     <%= f.label :password, "Password (at least 6 characters):" %>   </div>   <div>     <%= f.password_field :password %>   </div>

<% password_error = false

@user.errors.full_messages.any? do |error|   if error.match /password/i     password_error = true   end end %>

<% if password_error %>   <div class="field_with_errors"> <% end %>     <div class="field ">       <%= f.label :password_confirmation, "Password confirmation:" %>     </div>     <div>       <%= f.password_field :password_confirmation %>     </div> <% if password_error %>   </div> <% end %>

  <div class="actions">     <%= f.submit "Sign up" %>   </div> <% end %>

To move that code to a partial, is the solution to use @f in form_for()?

This is what I did:

views/users/new.html.erb:

<h1>Sign up</h1>

<%= form_for(@user) do |f| %> <% @f_for_partial = f %>

  <%= render 'shared/error_messages' %>

  <div class="field">     <%= f.label :name, "Name:"%>   </div>   <div>     <%= f.text_field :name %>   </div>

  <div class="field">     <%= f.label :email, "Email:" %>   </div>   <div>     <%= f.text_field :email %>   </div>

  <div class="field">     <%= f.label :password, "Password (at least 6 characters):" %>   </div>   <div>     <%= f.password_field :password %>   </div>

  <%= render 'users/password_confirmation_fix' %>

  <div class="actions">     <%= f.submit "Sign up" %>   </div> <% end %>

views/users/_password_confirmation_fix.html.erb:

<% password_error = @user.errors.full_messages.any? do |error|   error.match /password/i end %>

<% if password_error %>   <div class="field_with_errors"> <% end %>

    <div class="field ">       <%= @f_for_partial.label :password_confirmation, "Password confirmation:" %>     </div>     <div>       <%= @f_for_partial.password_field :password_confirmation %>     </div>

<% if password_error %>   </div> <% end %>

And in the action I did this:

  def create # POST requests to '/users' routes here     @user = User.new(params[:user])

    if @user.save       flash[:success] = "Welcome to the website."       redirect_to @user #goes to user 'show' page     else       @title = 'Sign up'

      #If password errors, then erase passwords.       #If no password errors, redisplay passwords.       if @user.errors.full_messages.any? {|error| error.match /password/i}           @user.password = ''           @user.password_confirmation = ''       end       render 'new'     end   end