I would like to alert something after my form has been updated
This is my code for the update method:
def update
node_id = session[:node_id]
@node = Node.find(node_id)
respond_to do |format|
if @node.update_attributes(params[:node])
format.html {redirect_to add_loc_path(:node_id=>session[:node_id])} #redirects use to current page
format.js #allowing the update method to respond to JavaScript
end
end
end
This is the code of the form:
<% form_for @expression, :url => { :controller => "expressions", :action => "update" } do |f| %>
...
<%= link_to_remote "say Hello", :url => { :controller => "expressions", :action => "update" }, :method => :get %>
<%= f.submit 'Update' %>
<% end %>
update.js.rjs:
page.alert('Hello')
If i click on the remote link ‘say Hello’, the content of ‘update.js.rjs’ is alerted. However if i click on the ‘Update button’, nothing is alerted, in fact i get the error:
try {
alert("Hello");
}
catch (e) { alert('RJS error:\n\n' + e.toString()); alert('alert(\"Hello\");'); throw e }
I don’t understand why update.js.rjs seems to work fine for ‘link_to_remote’ but gives an error when being called after clicking on the <%= f.submit 'Update' %> button
Is it possible to execute the contents of a rjs file after clicking on the Update button??
You should be using a
remote_form_forinstead of the normalform_for.