0

When using respond_to, my AJAX call only invokes the javascript response if the HTML response isn't present.

I have the following javascript for submitting an edit-in-place action:

$(".eip").editable("/surveys", {
  name   : 'survey[name]',
  select : true,
  event  : 'edit',
  submit : 'Save',
  cancel : 'cancel',
  cssclass : "editable",
  onblur : 'ignore',
  onedit : function() { $(".eip_desc").hide(); },
  onreset : function() { $(".eip_desc").show(); },
  onsubmit : function() { $(".eip_desc").show(); }
});

Then I have the following Survey controller method:

class SurveysController < ApplicationController
  def create
    @survey = Survey.new(params[:survey])    

    if @survey.save
      respond_to do |format|
        format.html { redirect_to surveys_path, :notice => "Survey created!" }
        format.js
      end
    else
      render :action => :new
    end
  end
end

If I remove the format.html line, then format.js responds as it should. But if I leave format.html in there, then the whole page renders when I submit via that editable javascript bit.

I'm running Rails 3.0.3 for this app.

Shpigford
  • 24,748
  • 58
  • 163
  • 252

1 Answers1

1

from docs

(String) method: Method to use when submitting edited content. Default is POST. You most likely want to use POST or PUT. PUT method is compatible with Rails.

try to pass a method: "put"

andrea
  • 3,515
  • 2
  • 22
  • 14
  • is right(Off Topic: but PUT could be used (in the right way) both to create or update. if you know how to naming your resource PUT could be the right coiche). maybe is the action wrong in this case , an edit-in-line have to be served by an update action. sorry for my english – andrea Jan 28 '11 at 02:32