views:

26

answers:

1

When showing a project, the user can add a decision via a form_for and its partial. Is there some way of avoiding reloading the page and just creating the record silently? In the controller method (adddecision) I have:

respond_to do |format|
      if @decision.save
        format.html { redirect_to(@project) }
        format.xml  { head :ok }
      else
        format.html { render :action => "show" }
        format.xml  { render :xml => decision.errors, :status => :unprocessable_entity }
      end

I've tried redirect_to(:back) etc - still getting a page reload.

A: 

Use remote_form_for to submit the form in the background via Ajax.

- remote_form_for :decision, :url => adddecisions_path(:format => 'xml') do
  = submit_tag

You can handle the error case (and the success case, if you like) in JavaScript. See the docs.

Jonathan Julian
Jonathan - doesn't remote_form_for rely on Prototype? I'm trying to go all jQuery. Using two jQuery plugins: form and validate did the trick.
Bob Walsh
You got it - `form_for` and `jquery.form` is what you need.
Jonathan Julian