使用时respond_to
,我的 AJAX 调用仅在 HTML 响应不存在时才调用 javascript 响应。
我有以下 javascript 用于提交就地编辑操作:
$(".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(); }
});
然后我有以下调查控制器方法:
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
如果我删除该format.html
行,format.js
则按应有的方式响应。但是如果我离开format.html
那里,那么当我通过那个editable
javascript 位提交时,整个页面都会呈现。
我正在为这个应用程序运行 Rails 3.0.3。