Refresh combobox with data from another Rails table

0

I have a "professions" field that appears inside the "patient" table. The field "professions" is autocomplete with gene chosen. I want to create a "new profession" button where when searching the combobox and not finding the desired profession, click on the new profession button and open a field to enter the new data. The problem is: clicking save the screen can not update, just the listing of professions in the combobox. I was able to pull the professions field into the "patient" table but when I click save, it is redirected to / professions.

I'm using AJAX, JQuery and Rails 4.2.

create.js.erb
$('#new-profession form').remove();
$('#new-profession a').show();
$('div#new-profession').appendTo("<%= j render @pacient %>")

Field profession on form.erb:

 <div class="col-md-3 col-sm-12 col-xs-12 form-group">
                  <label class="heard">Profissão:</label>
                  <div class="input-group col-md-12 col-sm-12 col-xs-12 form-group">
                    <%= f.select :profession_id,
                      Profession.all.map { |u| [u.description, u.id] },
                      { include_blank: "Buscar Profissão" },
                      { class: 'chosen-select' }
                    %>
                    <span class="input-grou-btn">
                        <div id="new-profession">
                        <%= link_to 'Adicionar Profissão', new_profession_path, remote: true %>
                      </div>
                    </span>
                  </div>
                </div>  

new.js.erb:

$('#new-profession a').hide().parent().append("<%= j render 'form', pacient: @pacient %>");
    
asked by anonymous 13.11.2018 / 00:20

0 answers