i have an model, which i want to show edit and update in a dialog via ajax.
What i do at the moment:
To open the Modal and render the partial, i send an ajax request to controller#show with ujs
this is the link:
<a class="person-dialog" data-remote="true" data-type="script" href="/en/people/32" onclick="return false">Fidel Markus Armstrong</a>
this runs the script in new.js.erb which renders the show partial inside the dialog and opens it.
To get the edit form, i do the same
<a class="person-dialog" data-remote="true" data-type="script" href="/en/people/32/edit" onclick="return false">Fidel Markus Armstrong</a>
this runs edit.js.erb
Now: To update my model, i send the form data as json to the controller#update
<form accept-charset="UTF-8" action="/en/people/32" class="form-horizontal" data-remote="true" data-type="json" id="edit_person_32" method="post">
if there is an error in the form, i do render_to_string(form_partial) inside the controller and respond with this inside of the json response.
Now i have the partial html inside of the json object. I do this, to get the rails error messages and fields_with_errors.
Is there a better way to do it? all the mix between script and json format and the partial html inside the json doesn't feel right.
This is the ajax for the form submit: