For example, I have project models and categories:
# project.rb
has_and_belongs_to_many :categories
# category.rb
has_and_belongs_to_many :projects
In the interface I need:
- Show input for project category name
- Suggest / autocomplete a category by name, if one exists
- If this does not exist, I need to dynamically create it and insert the name into the input and hold the identifier, then send the identifier to the server when the user submits the form.
So, I have a category controller that has search and create methods . The search returns in JSON format pairs of ID and NAME from the proposed categories; create saves the category to the database and returns a pair of identifiers and NAME when the user enters a new category into the input. This applies to entering several categories.
, , has_and_belongs_to, own_to. , .
Select2 select libs , , , .
- ?