Several edit pages have sections for editing associations that use multi-select boxes with huge lists in them. These are being replaced by a search box the will display a list of of entities from the associated table and offer the user the opportunity toggle the "linked" status of each displayed entity--that is, unlink linked entities and link unlinked entities.
Here is a list of files that need to be revised. We'll call the primary table being edited "primary" and the associated table "associate".
These files need to be added:
[Note: The convention for Rails join tables is to alphabetize the names, and this convention was also used in naming some of the templates and corresponding actions. To maintain this convention, some of the file names above should be altered if
associate alphabetically. In this case, the file names to use will be
rem_associate_primary.js.erb in place of the names given above, and the names of actions and references to these files in the files themselves will have to be adjusted accordingly.]
Here are step-by-step instructions for making the required changes. The changes in place for editing sites associated with a citation may serve as a model (see the controller file
citations_controller.rb and the template files in
app/views/citations; in the case of the template files, these can simply be copied and a search and replace done to replace the primary and associated table names (use the singular form when doing this):
_edit_primary_associate.html.erb partial (copy e.g.
app/views/citations/_edit_citations_sites.html.erb and replace
site with the appropriate strings).
routes.rb file, adding a member route of the form
get :search_associate to the resources for
Add a search (
search_associate) action to the controller.
If needed, add a search scope to the model for
associate (or write the action in step 5 in a way so that one isn't required).
At this point searching associates on the edit page should work. (If needed, add an instance variable for the associated collection to the
edit action of the controller so that it handles
js format. (
render layout should be
false, and additional template variables may have to be defined in the action.) Also, alter the update action to be ensure that if it renders the edit template on error, it has the variables it needs.
At this point the "Show only related ..." that appears after doing a search should be functional.
routes.rb, rename the
:edit_primary_associate route to
:add_primary_associate and change the method from
Rename the corresponding action in the controller and revise this action (use
CitationsController#add_citations_sites as a model).
At this point, linking an associated entity to the primary entity by clicking on the
+ sign should work.
In the controller, revise the
rem_primary_associate action (use
CitationsController#rem_citations_sites as a model).
At this point, unlinking an associated entity to the primary entity by clicking on the
X should work. The "Update" link that appears next to the "Existing Sites Relationships" table caption after unlinking an associate should now work and should erase from view the entity you just unlinked.