在ruby和rails服务器上使用mechanize进行put操作



我试着在rails服务器上放一个,我得到这个错误:send_request_with_body:未定义的方法'bytesize' # (NoMethodError)这是ruby代码:

agent = Mechanize.new
agent.basic_auth('user@gmail.com', '12345678')

a = agent.put('http://localhost:3000/thermostats/26.json',{ "thermostat[serial]" => "1",   "thermostat[temperature]" => 50,   "thermostat[humidity]" => 122222, "thermostat[user_id]" => 6 })

这是你想要执行的控制器的代码put

# PATCH/PUT /thermostats/1.json

def update
respond_to do |format|
  if @thermostat.update(thermostat_params)
    @thermostat.history_thermostats.create(temperature:@thermostat.temperature, humidity: @thermostat.humidity, energy: @thermostat.energy)
    format.html { redirect_to @thermostat, notice: 'Thermostat was successfully updated.' }
    format.json { head :no_content }
  else
    format.html { render action: 'edit' }
    format.json { render json: @thermostat.errors, status: :unprocessable_entity }
  end
end
end

根据李·贾维斯的回答。

@agent。把(uri,"{"关键":"val ","关键": " val "} ",{"内容类型"=> " application/json "})

相关内容

  • 没有找到相关文章

最新更新