When submitting a form with complex nesting to a Rails controller, the Javascript tied to the submit button is crucial. Here's an example:
$('#new_search').submit(function() {
var valuesToSubmit = $(this).serializeArray();
$.ajax({
type: "POST",
url: $(this).attr('action'), //submits it to the given url of the form
data: valuesToSubmit,
dataType: "POST"
})
return false; // prevents normal behavior
});
The Rails controller successfully handles this and ensures that all parameters are in place.
Following that, I render a js.erb file:
respond_to do |format|
format.js { render '/searches/update_search_results.js.erb' }
end
The log confirms that the file has been rendered:
Rendered searches/update_search_results.js.erb (0.3ms)
However, even a simple alert("hello world"); within the js.erb file is not triggering. There are no reported Javascript errors in the console log. Could the issue be related to the original Javascript that sends the Ajax request? Any suggestions or insights would be greatly appreciated. Thank you!