开发者

respond_to not working with format.js if format.html is present

开发者 https://www.devze.com 2023-02-07 07:18 出处:网络
When using respond_to, my AJAX call only invokes the javascript response if the HTML response isn\'t present.

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.


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"

0

精彩评论

暂无评论...
验证码 换一张
取 消