Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
¿Cómo actualizar un objeto DOM modal después de llamar al método con JS on Rails 5.2?

Estoy tratando de lograr algo que suena simple, pero que falla en este contexto particular.

Una instancia de Tarea se muestra en una ventana modal. La vista Mostrar modal incluye un formulario que, cuando se envía, activa el método de verificación en el controlador de tareas. El método actualiza un campo y el cambio debe reflejarse en la vista Mostrar actual.

Desafortunadamente, Rails genera un error UnknownFormat , reclamando una plantilla html.

También traté de representar el fragmento de JavaScript directamente dentro del método con: render js: "document.getElementById('task-git-hash').value = ('#{ @task.git_hash }');" pero el código se representa literalmente como una nueva página html, en lugar de ejecutarse en la vista actual.

vista modal show.html.erb (extracto)

 <%= 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 %>

método task_controller

 def verify ### Retrieved by Callback function @task.update_attribute(:git_hash, Time.now.strftime("Tested at %H:%M")) end

verificar.js.erb vista

 document.getElementById("task-git-hash").value = ("<%= @task.git_hash %>");

¿Cómo puedo hacer para actualizar este campo en la vista actual cuando se valida el formulario?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!