I am trying to achieve something that sounds simple, but that fails in this particular context.
A Task instance is displayed in a modal window. The modal Show view includes a form which, when submitted, triggers the verify method in the tasks_controller. The method updates a field, and the change should be reflected in the current Show view.
Unfortunately, Rails raises an UnknownFormat error, claiming for a html template.
I also tried to render the javaScript snippet directly inside the method with: render js: "document.getElementById('task-git-hash').value = ('#{ @task.git_hash }');" but the code is rendered literally as new html page, instead of being executed in the current view.
show.html.erb modal view (extract)
<%= form_with model: @task, url: :verify_task, method: :post, html: {id: "verify_form"}, remote: true do |f| %>
<div class="row mat-form-row">
<div class="mat-form-field col-md-4">
<label for="task-git-hash" class="mat-form-field-label">
<%= t('tasks.show.GitHash') %>
</label>
<input id="task-git-hash" class="mat-input-element" readonly
value="<%= @task.git_hash %>" />
</div>
<div class="mat-form-field col-md-6">
<%= f.label :verify_on_technology_id, t('tasks.show.Technology'), class: "mat-form-field-label" %>
<%= f.grouped_collection_select :verify_on_technology_id,
values_options_for('Technologies', 1, @task.technology_id), # group
:subs, # descendants
:code, # group label
:id, :code, # option key & label
{:include_blank => false},
{ class: "mat-input-element select2-candidate" } %>
</div>
<div class="mat-form-field col-md-2">
<%= f.label :git_hash, t('tasks.show.GetHash'), class: "mat-form-field-label" %>
<button class="mat-flat-button mat-button-base mat-primary">
<%= t('Verfiy') %>
</button>
</div>
</div>
<% end %>
tasks_controller method
def verify
### Retrieved by Callback function
@task.update_attribute(:git_hash, Time.now.strftime("Tested at %H:%M"))
end
verify.js.erb view
document.getElementById("task-git-hash").value = ("<%= @task.git_hash %>");
How can I manage to update this field in the current view when the form is validated?