2014-05-16 2 views
0

레일 :이 루비 코드 # (NoMethodError) 에 대한 정의되지 않은 메서드 'bytesize': 'send_request_with_body을'루비의 기계화와 풋을하고 나는이 오류를 얻을 레일 서버에 넣어 만들려고 서버

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 
+0

#put에 대한 문서를 읽고, 두 번째 인수는 문자열이 아닌 해시해야한다 : https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize.rb#L533 –

+0

무엇 "엔터티"에 넣어야합니까?, 컨트롤러의 이름입니까? – user2994005

+0

대답을 알아 냈습니까? –

답변

0

입니다. 이것은 나를 위해 일했다.

@agent.put(uri, "{\"key\": \"val\",\"key\": \"val\"}", {"Content-Type" => "application/json"})