2014-05-16 1 views
0

j'essaie faire mettre dans un serveur de rails, je reçois cette erreur: « send_request_with_body »: méthode non définie « bytesize » pour # (NoMethodError) c'est le code ruby:faire une vente avec mécaniser Ruby et Rails serveur

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 }) 

et c'est le code du contrôleur que vous voulez faire mettre

# 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

Lisez la documentation pour #place, le second argument doit être une chaîne, pas un hachage: https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize.rb#L533 –

+0

Qu'est-ce que devrais-je mettre dans "entité" ?, Est-ce que le nom du contrôleur? – user2994005

+0

Avez-vous trouvé la réponse? –

Répondre

0

travail hors de la réponse de Lee Jarvis. Cela a fonctionné pour moi.

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

Questions connexes