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
(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
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 + “ ”
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