Choosing Rails with Suggestions and Deleted Data

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 , , , .

- ?

+4
2

Ryan Bates RailsCasts. find_or_create, , jQuery Tokeninput.

select2, , Ryan , select2.

+2

, ProjectCategoryBeloning, "" Project Category: has_many has_many_and_belongs_to. Project , ui . jquery.ui: https://jqueryui.com/autocomplete/, AJAX.

+1

All Articles