Strange update_attributes behavior

Okay, let me explain my problem. I've got a form that looks like this:

- form_remote_for item, :url => list_item_path(item.list, item) do |f|   %p     = f.check_box :completed, :onclick => 'this.form.onsubmit()', :index => item.id     = f.text_field :content, :readonly => 'readonly', :index => item.id, :onblur => 'this.form.onsubmit()'     = link_to_remote "(edit)", :url => edit_list_item_path(item.list, item), :method => :get

It's written in HAML. As you can see there are a couple of special things about this form:

1. I'm using the :index option for the fields because there are multiple Item forms on the same page.

2. The 'content' text field is readonly, but when the user clicks the "(edit)" link that attribute will be removed to enable the user to edit the field.

3. The form gets submitted when the user clicks the check box or presses enter or sets the 'content' field _out_ of focus.

The action that the form gets submitted to looks like this:

def update   @list = current_user.lists.find(params[:list_id])   @item = @list.items.find(params[:id])   @item.update_attributes(params[:item][@item.id]) end

And here is the log message:

Processing ItemsController#update (for 127.0.0.1 at 2008-08-01 10:59:05) [PUT]   Session ID: BAh7CDoMY3NyZl9pZCIlNmFiNjYzYmNjNDMwMGY5NzZmZGVkZjcwZTIxZDVk YWU6DHVzZXJfaWRpBiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxh c2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--8c3643dc2753649acded627430ae5f60037b36f8   Parameters: {"authenticity_token"=>"d1ada56a0fe0d5d80601c65215ef262e940e56bb", "_method"=>"put", "action"=>"update", "id"=>"37", "list_id"=>"6", "controller"=>"items", "item"=>{"37"=>{"completed"=>"0", "content"=>"abc"}}}   e[4;36;1mUser Columns (0.015000)e[0m e[0;1mSHOW FIELDS FROM `users`e[0m   e[4;35;1mUser Load (0.000000)e[0m e[0mSELECT * FROM `users` WHERE (`users`.`id` = 1) LIMIT 1e[0m   e[4;36;1mList Columns (0.000000)e[0m e[0;1mSHOW FIELDS FROM `lists`e[0m   e[4;35;1mList Load (0.000000)e[0m e[0mSELECT * FROM `lists` WHERE (`lists`.`id` = 6 AND (`lists`.user_id = 1)) e[0m   e[4;36;1mItem Columns (0.016000)e[0m e[0;1mSHOW FIELDS FROM `items`e[0m   e[4;35;1mItem Load (0.016000)e[0m e[0mSELECT * FROM `items` WHERE (`items`.`id` = 37 AND (`items`.list_id = 6)) e[0m   e[4;36;1mSQL (0.000000)e[0m e[0;1mBEGINe[0m   e[4;35;1mSQL (0.000000)e[0m e[0mCOMMITe[0m Rendering items/update   e[4;36;1mItem Load (0.000000)e[0m e[0;1mSELECT * FROM `items` WHERE (`items`.list_id = 6) AND (`items`.`completed` = 0) ORDER BY positione[0m   e[4;35;1mList Load (0.000000)e[0m e[0mSELECT * FROM `lists` WHERE (`lists`.`id` = 6) e[0m Rendered items/_item (0.03100)   e[4;36;1mCACHE (0.000000)e[0m e[0;1mSELECT * FROM `lists` WHERE (`lists`.`id` = 6) e[0m Rendered items/_item (0.00000)   e[4;35;1mCACHE (0.000000)e[0m e[0mSELECT * FROM `lists` WHERE (`lists`.`id` = 6) e[0m Rendered items/_item (0.01500)   e[4;36;1mCACHE (0.000000)e[0m e[0;1mSELECT * FROM `lists` WHERE (`lists`.`id` = 6) e[0m Rendered items/_item (0.01600)   e[4;35;1mCACHE (0.000000)e[0m e[0mSELECT * FROM `lists` WHERE (`lists`.`id` = 6) e[0m Rendered items/_item (0.00000) Completed in 0.29700 (3 reqs/sec) | Rendering: 0.11000 (37%) | DB: 0.04700 (15%) | 200 OK [http://localhost/lists/6/items/37\]

As you can see the Item is not getting updated at all. But it renders the update.rjs template anyway and rerenders all the _item partials which contains the forms I just showed you.

Anyone who can see the problem. Please take a close look at the log message like I did. It must have made me blind to stare at this. If you need any further information, please just ask.

Thanks in advance, David Trasbo.

As you can see the Item is not getting updated at all. But it renders the update.rjs template anyway and rerenders all the _item partials which contains the forms I just showed you.

Failing validations ?

Fred

Frederick Cheung wrote:

As you can see the Item is not getting updated at all. But it renders the update.rjs template anyway and rerenders all the _item partials which contains the forms I just showed you.

Failing validations ?

No, actually there are no validations to fail. ):

Frederick Cheung wrote:

As you can see the Item is not getting updated at all. But it
renders the update.rjs template anyway and rerenders all the _item partials which contains the forms I just showed you.

Failing validations ?

No, actually there are no validations to fail. ):

I'd change update_attributes to update_attributes! (which will raise
errors if necessary). Also check that activerecord's (new in 2.1) dirty change tracking
isn't tripping you up (save will be a no-op if there aren't any
changes to make)

Fred

Another thought, if you have a association called transaction, then scrap it (that breaks stuff because it will replace a method on ActiveRecord)

Fred

Frederick Cheung wrote:

As you can see the Item is not getting updated at all. But it
renders the update.rjs template anyway and rerenders all the _item partials which contains the forms I just showed you.

Failing validations ?

No, actually there are no validations to fail. ):

Another thought, if you have a association called transaction, then scrap it (that breaks stuff because it will replace a method on ActiveRecord)

I don't. I think I already tried the bang method, but I'll try again and tell you about the result. If anyone's got an idea, please tell.

David Trasbo wrote:

Another thought, if you have a association called transaction, then scrap it (that breaks stuff because it will replace a method on ActiveRecord)

I don't. I think I already tried the bang method, but I'll try again and tell you about the result. If anyone's got an idea, please tell.

No, the bang method doesn't work either... By the way here is the model:

class Item < ActiveRecord::Base   belongs_to :list   named_scope :complete, :conditions => { :completed => 1 }, :order => :position   named_scope :incomplete, :conditions => { :completed => 0 }, :order => :position end

David Trasbo wrote:

Another thought, if you have a association called transaction, then scrap it (that breaks stuff because it will replace a method on ActiveRecord)

I don't. I think I already tried the bang method, but I'll try
again and tell you about the result. If anyone's got an idea, please tell.

No, the bang method doesn't work either... By the way here is the
model:

In that case I'd try stepping through update_attributes with the
debugger and see where it goes wrong.

Fred