我有一个标准控制器,用于响应HTML、JS和JSON请求:
def picture
@picture = Picture.new params[:picture]
respond_to do |format|
if @picture.save
format.html do
logger.debug "In the HTML responder"
redirect_to @picture
end
format.json { render json: @picture, status: :created, location: @picture }
format.js { render :nothing => true }
else
# you get the idea
end
end
end
现在,我正试图用$.ajax
函数向该控制器发送一个请求(在这种特定情况下,我不能使用:remote => true
——我正试图让ajax文件上传工作正常).
$.ajax({
url: $("form#new_picture").attr("action"),
type: "POST",
data: formdata,
processData: false,
contentType: false
});
问题是,出于某种原因,我的请求被视为HTML请求.如何告诉rails我需要JS响应?
顺便说一句,我在我的项目中使用jquery_ujs,所以如果需要,我可以访问它提供的方法.我在JS方面做得还不够好,无法调整它来满足我的需要.