0
我嘗試做一個滑軌服務器看跌我得到這個錯誤: 「send_request_with_body」:未定義的方法「bytesize」爲#(NoMethodError) 這是Ruby代碼:使紅寶石機械化看跌期權和軌道服務器
agent = Mechanize.new
agent.basic_auth('[email protected]', '12345678')
a = agent.put('http://localhost:3000/thermostats/26.json',{ "thermostat[serial]" => "1", "thermostat[temperature]" => 50, "thermostat[humidity]" => 122222, "thermostat[user_id]" => 6 })
,這是你想要做的控制器的工作關李·賈維斯的回答的代碼把
# 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
閱讀#put的文件,第二個參數應該是一個字符串,而不是一個哈希:https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize.rb#L533 –
什麼我應該放入「實體」嗎?, 是否是控制器的名稱? – user2994005
你有沒有想出答案? –