I need to pre-select multiple values in a select_tag. But I'm adding the vacancies 'manually' in table vacancies as follows:
My controller:
def create
@hr_curriculum_generic = HrCurriculumGeneric.new(params[:hr_curriculum_generic])
if params[:vacancy_ids].present?
@vacancies_ids = params[:vacancy_ids]
-- my form:
@vacancies_ids.each do |vacancy_id|
# Armazena os id do curriculum, vaga e do cargo na tabela CandidatosxVagas
@candidates_vacancies = CandidatesVacancy.new
<% @vacancies = Vacancy.all %>
<%= select_tag "vacancy_ids[]", options_from_collection_for_select(Vacancy.all, "id", "title"), :multiple => true, :id => "vacancy_ids", :class => "form-control" %>
.....
It works, but when I click in the edit btn, the fields are not being pre-selected.