这里发生了什么?我正在尝试通过JSON数据类型的ajax调用添加数据。但每次尝试添加数据时,它都显示如图所示的错误。
我认为它总是响应于HTML格式,但不响应JSON格式。
def new
@batch = Batch.new
respond_to do |format|
format.json
format.html
end
end
def create
@batch = Batch.new(batch_param)
puts "/n/n/n/n name: #{@batch.name} /n/n/n/n"
respond_to do |format|
if @batch.save
format.json { render json: @batch, status: :created, location: @batch }
format.html { redirect_to @batch, notice: "Save process completed!" }
else
format.html {
flash.now[:notice]="Save proccess coudn't be completed!"
render :new
}
format.json { render json: @batch.errors, status: :unprocessable_entity}
end
end
end
before_filter
替换为before_action
。免费的 Atom 文本编辑器具有相当不错的查找和替换功能,可在整个项目目录中使用。否则,您可以使用 grepgrep -rl before_filter app/controllers | xargs sed -i 's/before_filter/before_action/g'
。 - max