Rails REST使用Firefox RESTclient

时间:2015-12-17 22:00:06

标签: ruby-on-rails

我试图将REST输入测试到Rails 3应用程序中。我正在使用名为RESTclient的Firefox插件。对于州议员,我只是试图在数据库中输入(更新)一列(contact2 =" Bart")。

我返回200,但列未在数据库中更新,并且响应显示该列仍包含" Mary2"

这是一张照片:

enter image description here

这是控制器:

public static final int DOWNLOAD_CHUNK_SIZE = 2048; //Same as Okio Segment.SIZE

try {
        Request request = new Request.Builder().url(uri.toString()).build();

        Response response = client.newCall(request).execute();
        ResponseBody body = response.body();
        long contentLength = body.contentLength();
        BufferedSource source = body.source();

        File file = new File(getDownloadPathFrom(uri));
        BufferedSink sink = Okio.buffer(Okio.sink(file));

        long totalRead = 0;
        long read = 0;
        while (read = (source.read(sink.buffer(), DOWNLOAD_CHUNK_SIZE)) != -1) {
            totalRead += read;
            int progress = (int) ((totalRead * 100) / contentLength);
            publishProgress(progress);
        }
        sink.writeAll(source);
        sink.flush();
        sink.close();
        publishProgress(FileInfo.FULL);
} catch (IOException e) {
        publishProgress(FileInfo.CODE_DOWNLOAD_ERROR);
        Logger.reportException(e);
}

Rails日志:

  # PUT /workorders/1
  # PUT /workorders/1.json
  def update
    @workorder = Workorder.find(params[:id])

    respond_to do |format|
      if @workorder.update_attributes(params[:workorder])
        format.html { redirect_to @workorder, notice: 'Workorder was successfully updated.' }
        format.json { render json: @workorder }
      else
        format.html { render action: "edit" }
        format.json { render json: @workorder.errors, status: :unprocessable_entity }
      end
    end
  end

是参数" contact2"没被送到?

1 个答案:

答案 0 :(得分:0)

我使用Wiztools RESTclient工作了。

我不得不使用:

Body = application / json;字符集= UTF-8  {     “contact2”:“巴特”  }