0

这是我的ajax

$.ajax({
    data: {id: 1,status: 1},
    success: function(data){
    Collection.success_res();
    },
    error: function(data){
    Collection.error_res();
    }
})

这是我的控制器

def update_status
    @post = Post.find params[:id]
    if @post.update_attributes params[:status]
      respond_to do |format|
      end
    end

  end

我收到错误

undefined method `stringify_keys' for "1":String
4

1 回答 1

0

$.ajax 调用看起来并不完整,而且字段名称应该在 JSON 中用引号引起来。尝试 :

var mydata = {"id": 1,"status": 1}

$.ajax({
    type: "POST",
    dataType: "json",
    url: "your post URL goes here",
    data: mydata,
    success: function (data) {
        alert('success');
    },
    error: function (error) {
        alert("something went wrong");
    }
});
于 2013-10-08T18:18:54.223 回答