I’ve got an observe_form method that calls a remote action (when any
of the form fields are modified) and then simply displays the result
in a div tag. Generic. I can’t for the life of my figure out why my
observe_form, when triggered, is NOT calling its specified action but
instead triggers the submit action on the form itself. wtf?!? The
Ajax action never gets called. Instead the form gets submitted and
the update action called.
There’s some kind of weird cross-talk going on between the two. I’ll
include the entire view code since it’s pretty simple:
<% form_for(:report, :url => {:controller => ‘reports’, :action =>
‘update’},
:html => {:method => “put”, :id=>“report-form”}) do
|form|
%>
<%= text_field ‘report’, ‘name’, :size => 50 %>
<div id="df-result"> </div>
<%= submit_tag 'Update' %>
<% end %>
<%= observe_form “report-form”,
:url => { :action => :calculate_df},
:frequency => 1,
:update => “df-result”,
:complete => “Element.show(‘df-result’)” %>
Check out the request parameters when a field is modified:
{“commit”=>“Update”,
“_method”=>“put”,
“authenticity_token”=>“012fb6561f2e8a04cc5f391c34c9018467b12a7f”,
“id”=>“calculate_df”,
“report”=>{“name”=>“Blahdisd”}}
What the heck?? Check out the id. When a field is modified, instead
of calculate_df getting called, the update action gets triggered and
the id of the form object gets set to the name of the ajax action,
calculate_df !!
The create form works just fine and calls the Ajax method as it should
and posts properly when submitted, i.e., everything works fine here:
<% form_for(:report, @report, :url => {:action => "create"},
:html => {:method => :post, :id=>"report-
form"}) do |form|%>
I’m using rails 2.0.2 and reports are RESTful.
I found this bug which may or may not be the same one that’s biting me:
http://dev.rubyonrails.org/ticket/6662
Anyone encounter this? Am I missing something?
–russ