Model validation outside of the model

Hi, having trouble validating my form:

_form.html.erb:
  <% form_remote_for :user, @user, :url => { :action => "create" } do

f> %>

    <table class="table">
    <tr>
      <td colspan="2" class="center"><div id="notice"><br /></div> </td>
    </tr>
    <tr>
      <td class="text">Email:</td>
      <td><%= f.text_field :email %></td>
    </tr>

    <tr>
      <td class="text">Password:</td>
      <td><%= f.text_field :password %></td>
    </tr>

      <tr>
        <td></td>
        <td align="right">
            <%= submit_tag "Add user" %>
        </td>
      </tr>

    </table>
  <% end %>

controller:
  def create
    @user = User.new(params[:user])

    if @user.save
     if(request.xhr?)
      render :update do |rjs|
          flash[:notice] ="<font class='notice-obj'>" + @user.email +
"</font><font class='notice-pos'> was added successfully!</font>"

          rjs.replace_html "notice", :partial => 'notice'
          rjs.visual_effect(:highlight, "notice", :startcolor =>
"#D6D6D6", :endcolor => "#ffffff", :duration => 2)
        end
      else
        redirect_to_index and return
      end
    end
  end

On the surface, it seems that if a user enters invalid info into the
fields, it doesn't make it to the redirect_to_index at all. In fact,
when I put a flash[:notice] into the else and submit invalid info, it
doesn't make it. That's problem #1.

I guess problem #2 follows #1. Where would I put <%= error_messages_for
'user' %>, if that's the right way to do it, firstly.

Thanks!

On the surface, it seems that if a user enters invalid info into the
fields, it doesn't make it to the redirect_to_index at all. In fact,
when I put a flash[:notice] into the else and submit invalid info, it
doesn't make it. That's problem #1.

Have you read through your code? cutting out the fluff it does

if @user.save
...
end
i.e. nothing happens if the user isn't valid. Looks like you flipped
the request.xhr? test with the user validity one

I guess problem #2 follows #1. Where would I put <%= error_messages_for
'user' %>, if that's the right way to do it, firstly.

In your notice partial.

Fred

partial:
<%= flash[:notice] if flash[:notice] %>
<%= @user.errors %>

I get # for errors ?

You can't just dump a ruby object into your html like that (apart from
anything else the default string representation on an object has <> in
it, which confuses browsers. That's what error_messages_for is for (or
build your own replacement)

Fred