Q:

Rails remote forms validation

Just a simple question, I have followed the railscast
It's nice how for remote true works, but how can I validate the model ? 
I have this one
<%= form_for [:admin,@course], remote: true  do |f| %>
  <div class="field">
    <%= f.label :title, "The title:" %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :description, "Descripcion:" %><br />
    <%= f.text_area :description %>
 </div>
 <div class="actions">
   <%= f.submit "Send"%>
 </div>
<% end %>

How I handle the error?
def create

  @course = Course.new(params[:course])

  respond_to do |format|
    if @course.save
      format.html { redirect_to admin_index_url, :notice=> 'Done !!' }
      format.js
    else
      format.html { flash.now[:alert] = "Not done" 
                    render "new"
                  }
      format.js
    end
  end        
end

Any ideas why this does not work?

A:

Since your format.js blocks are empty,  and the create action is called via :remote=>true,  rails will do the default,  which is to look for create.js.erb to render back,  which it probably isn't finding.
To illustrate,  put this in the views directory in app/views/?/create.js.erb:
alert('HI');

Then put this in your controller to see an alternative:
respond_to do |format|
  if @course.save
    format.html { redirect_to admin_index_url, :notice=> 'Done !!' }
    format.js { render :js=>'alert("done");' }
  else
    format.html { flash.now[:alert] = "Not done" 
                render "new"
                }
    format.js { render :js=>'alert("not done");' }
  end
end        

So now,  you just have to get the error messages into the HTML/Javascript sent back,  probably the most railsy way is to just put it into the appropriate .js.erb file.

