Save 36% for Black Friday! Learn more

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do populate select box with filtered options in cocoons nested forms

hemmpa asked in Rails

Hi,

I have been having having a challenging problem as my rails skill is still not great.

I am using a cocoons gem to generate nested forms. I have three models Employee , Competence and Skill where I have just a basic associations.
in Employee model

 has_many :competences

and in Competence model

belongs_to :employee

So I am generating competences nested forms in employee form. And in competences form I have a skill attribute where I used a select box. This select box is populated with list of skills from the Skill model as below

      <%= f.collection_select :skill_id, Skill.all, :id, :skill_name, options={include_blank: true}, html_options={class: 'selectize', required: true} %>

What I wanted to achieve is that, in the skills select box I get all skills from the skills model regardless of that skill is already been selected in another competences form. So I wanted the select options are only those new skills which are not already selected in another nested competences form.

This is to avoid selection the same skill in the nested form more than once as it is difficult to see as the nested forms list grows.

Any suggestion is appricaited!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,110+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.