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.