It's not the only remote form I'm using, but I can't see the problem here. It's a simple table where every row has its own form and inline form fields.
<% for temporary_address in @temporary_addresses %>
<tr id="row-<%= temporary_address.id -%>">
<%= form_for temporary_address, :remote => true do |form| %>
<td>
<%= link_to "x", temporary_address, :method => :delete, :remote => true %>
<%= form.submit "s" %>
</td>
[... form fields ...]
<% end %>
</tr>
<% end %>
However, this only works when :remote => true is not used.
resources :temporary_addresses
is in the routes file. Delete links are working and the form is also working when not using :remote => true.
pressing submit with remote => true gives
Started POST "/temporary_addresses/12" for 127.0.0.1 at 2011-07-17 12:45:26 开发者_开发技巧+0200
ActionController::RoutingError (No route matches "/temporary_addresses/12")
and submitting without remote => true works with the following response
Started POST "/temporary_addresses/12" for 127.0.0.1 at 2011-07-17 12:46:15 +0200
Processing by TemporaryAddressesController#update as HTML
Parameters: {[...] "commit"=>"s", "temporary_address"=>{[...]}, "id"=>"12"}
does someone have a clue about this?
EDIT 1 Removed the link_to :remote to destroy a record to check. Same error...
A rendered form looks like this:
<tr id="row-1">
<td>
</td>
<form accept-charset="UTF-8" action="/temporary_addresses/1" class="edit_temporary_address" data-remote="true" id="edit_temporary_address_1" method="post">
<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" />
<input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="vpFbYO7L9fVtBsWej37FUBobraYjjdWA/F8AjWTwC7A=" />
</div>
<td>
<input id="temporary_address_firstname" name="temporary_address[firstname]" size="30" type="text" value="John" />
</td>
<td>
<input id="temporary_address_lastname" name="temporary_address[lastname]" size="30" type="text" value="Doe" />
</td>
<td>
<input id="temporary_address_email" name="temporary_address[email]" size="30" type="text" value="john.doe@example.com" />
</td>
<td>
New record
</td>
<td>
<input id="temporary_address_submit" name="commit" type="submit" value="save" />
</td>
</form>
</tr>
Solved!
Simple thing.. Firefox rearranges things when they're not valid html. The output given above is the source code. Now that I've seen the generated source code (thanks to web development toolbar) the problem is clear: The hidden form fields, generated in divs with display:none have been moved outside of the form.
精彩评论