Saturday, 15 January 2011

ruby - Rails update_attributes not updating record -



ruby - Rails update_attributes not updating record -

i have next code in "entries_controller.rb"

def update @entry = entry.find(params[:id]) puts "received http request update old entry:#{@entry.inspect} with" puts "new parameters: #{params}" if @entry.update_attributes(params[:entry]) puts"update successful" @entry2 = entry.find(params[:id]) puts "here new value #{@entry2.inspect}" end end

when send set request server client console shows this:

2013-02-17t20:12:25+00:00 app[web.1]: received http request update old entry:#<entry id: 1, created_at: "2013-02-17 19:17:40", updated_at: "2013-02-17 19:17:40", description: "test", title: "home", category: "-1", latitude: "49.258061", longitude: "-123.153972", hasphoto: false> 2013-02-17t20:12:25+00:00 app[web.1]: new parameters: {"description"=>"test", "id"=>"1", "category"=>"-1", "hasphoto"=>"0", "latitude"=>"49.258061", "longitude"=>"-123.153972", "title"=>"updated home", "action"=>"update", "controller"=>"entries", "format"=>"json"} 2013-02-17t20:12:25+00:00 app[web.1]: update successful 2013-02-17t20:12:25+00:00 app[web.1]: here new value #<entry id: 1, created_at: "2013-02-17 19:17:40", updated_at: "2013-02-17 19:17:40", description: "test", title: "home", category: "-1", latitude: "49.258061", longitude: "-123.153972", hasphoto: false>

as can see old record not updated. though if clause evaluated true. see value "title" didn't alter "home" "updated home".

im wondering whats bug in this? saying updated didn't update.

can help me understand please?

thanks

what's happening within view file not setting appropriate form in view. parameters returning this

{"description"=>"test", "id"=>"1", "category"=>"-1", "hasphoto"=>"0", "latitude"=>"49.258061", "longitude"=>"-123.153972", "title"=>"updated home", "action"=>"update", "controller"=>"entries", "format"=>"json"}

when in reality should returning this...

{"entry" => {"description"=>"test", "id"=>"1", "category"=>"-1", "hasphoto"=>"0", "latitude"=>"49.258061", "longitude"=>"-123.153972", "title"=>"updated home"}, "action"=>"update", "controller"=>"entries", "format"=>"json"}

notice difference? parameters regarding entry wrapped , attached attribute entry. way when rails looks @ parameters, knows parameters newly updated entry. without looking @ forms, there isn't way tell how prepare it, here's place start.

ruby-on-rails ruby http-post update-attributes

No comments:

Post a Comment