Hi guys,
can anyone explain how to show error_messages_on (like back in Rails 2 , without Ajax) fields that didnt' pass the validation the jquery way.
I googled for about 2 hours now and found nothing. Jquery works fine and adds the content to my table, but im totally stuck with the whole error/validation thing.
My form looks like this:
<%= form_for Translation.new , :remote => true do |f| %> <table> <tr> <td> <%= f.label :locale %><br /> <%= f.text_field :locale %>
</td> <td> <%= f.label :key %><br /> <%= f.text_field :key %> </td> </tr> <tr> <td> <%= f.label :value %><br /> <%= f.text_area :value , :rows => 3%> </td> <td> <%= f.label :interpolations %><br /> <%= f.text_area :interpolations, :rows => 3 %> </td> </tr> <tr> <td> <%= f.label :is_proc %><br /> <%= f.check_box :is_proc %> </td> <td></td> </tr> </table> <p><%= f.submit t('translation.create') %></p> <% end %>
Create action like this: def create if @translation.save flash[:notice] = "Successfully created translation." respond_to do |format| format.html { redirect_to @translation } format.js end else respond_to do |format| format.html { render :action => 'new'} # show what went wrong with jquery end end end
and create.js.erb /* Insert a notice between the last comment and the comment form */ $("#translation-notice").html('<div class="flash notice"><%= escape_javascript(flash.delete(:notice)) %></div>');
/* Add the new comment to the bottom of the comments list */ $("#translations").prepend("<%= escape_javascript(render(@translation)) %>");
/* Highlight the new comment */ $("#translation-<%= @translation.id %>").effect("highlight", {}, 3000);
/* Reset the comment form */ $("#new_translation")[0].reset();
Adding validated data works but please give me hint with error validation thing.
thanks