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!