# Resubmitting remote form via AJAX -- old parameters get passed!

**URL:** <https://www.ruby-forum.com/t/resubmitting-remote-form-via-ajax-old-parameters-get-passed/162529>\
**Category:** Rails\
**Created:** [March 10, 2009, 11:15pm UTC](https://www.ruby-forum.com/t/resubmitting-remote-form-via-ajax-old-parameters-get-passed/162529 "2009-03-10T23:15:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaveeno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/58956e/32.png) [@gaveeno](https://www.ruby-forum.com/u/gaveeno)\
**Post date:** [March 10, 2009, 11:15pm UTC](https://www.ruby-forum.com/t/resubmitting-remote-form-via-ajax-old-parameters-get-passed/162529/1 "2009-03-10T23:15:34Z")

</div>

When I submit a form via AJAX and get back some errors in my “errors”  
div, if I try to resubmit the form with the errors corrected it still  
passes the old parameters. See my code at: [http://pastie.org/413269](http://pastie.org/413269)  
(also pasted below). I can’t figure out why the 2nd time the form is  
submitted, it still has the old parameters even though the fields are  
populated with the new parameters. Anybody know why this could be?

## views/campaigns/\_edit.html.erb

\<% remote\_form\_for @campaign, :url =\> {:controller =\> :setup, :action  
=\> :update\_campaign, :id =\> @campaign },:html =\> {:id =\>  
‘campaign\_form’},  
:loading =\> “Element.show(‘campaign\_spinner’);”,  
:complete =\> “Element.hide(‘campaign\_spinner’);” do |campaign\_form|  
%\>  
\<%= render :partial =\> ‘campaigns/edit\_form\_contents’, :locals =\>  
{:form\_type =\> form\_type,:campaign\_form =\> campaign\_form} %\>  
\<% end %\>

## views/campaigns/\_edit\_form\_contents.html.erb

 ![](https://www.ruby-forum.com/images/1_25px.png)

 \<%= campaign\_form.label :description, "Description" %\> \<%= campaign\_form.text\_field :description, :class =\> 'custom span-8' %\> 

 ![](https://www.ruby-forum.com/images/2_25px.png)

 \<%= campaign\_form.label :start\_date, "Start date" %\> \<%= campaign\_form.calendar\_date\_select :start\_date, :time =\> false, :class =\> "span-4" %\> 

 \<%= button\_submit\_to\_remote "Save",{:icon=\>"accept",:submit\_form =\> 'campaign\_form',:size =\> "small"},"left","campaign\_spinner" %\> 

 ![](https://www.ruby-forum.com/images/spinners/%20spin_small_dark_blue.gif)

## helpers/setup\_helper.rb

def button\_submit\_to\_remote(name,options=  
{},alignment=nil,spinner=nil)  
path = {}  
position = get\_position(alignment)  
img\_tag = get\_image(options.delete(:icon) || “”)  
button\_type = get\_button\_size(options.delete(:size) || “”)  
link = (img\_tag ||= “”) + name + “&nbsp;”  
options.store(:class,“#{button\_type} #{position}”)  
submit\_form = options.delete(:submit\_form) || nil

```
if submit_form
  link_to_function link, options, :class => "#{button_type} #

```

{position}" do |page|  
page \<\< “Element.show(‘#{spinner}’);” if spinner  
page \<\< “$(‘#{submit\_form}’).onsubmit()”  
end  
end  
end

## controllers/campaigns\_controller.rb

def update  
@campaign = Campaign.find(params[:id])

```
respond_to do |format|
  if @campaign.update_attributes(params[:campaign])
    flash[:success] = 'Updates saved.'
    format.html { redirect_to setup_campaigns_path }
    format.js { redirect_to setup_campaigns_path }
  else
    flash.now[:error] = "Couldn't save campaign."
    format.html { redirect_to :action => 'edit'}
    format.js {
      render :update do |page|
      page.replace_html :errors, error_messages_for([:campaign])
      page << "window.scrollTo(0,0);"
      end }
  end
end

```

end

---

<div class="post-metadata">

**Author:** ![gaveeno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/58956e/32.png) [@gaveeno](https://www.ruby-forum.com/u/gaveeno)\
**Post date:** [March 10, 2009, 11:33pm UTC](https://www.ruby-forum.com/t/resubmitting-remote-form-via-ajax-old-parameters-get-passed/162529/2 "2009-03-10T23:33:45Z")

</div>

I realized that the form is actually sending the new parameters but I  
shouldn’t be using a remote form here if I want a redirect…the  
format.js {redirect\_to setup\_campaigns\_path } doesn’t actually  
redirect the browser.
