swt2-intro-exercise / rails-exercise-18-Kenneth-Schroeder

rails-exercise-18-Kenneth-Schroeder created by GitHub Classroom
MIT License
1 stars 0 forks source link

Edit paper page should allow to select paper authors from a multiple select box #18

Open swt2public opened 5 years ago

swt2public commented 5 years ago

Scenario

Given a paper When a user visits the paper's edit page Then it should have a single multiple select box

Hints

A paper can have many authors. An author can write many papers. This relationship of the models is indicated in Rails by annotating both models with a has_and_belongs_to_many association.

In order to store this new n:m relation, a new database table is needed. It is created in a migration. Help on the required migration can be found in the this documentation. There is also a generator which will produce join tables if 'JoinTable' is part of the name: rails generate migration CreateJoinTableAuthorPaper author paper Reminder: Migrations are stored in db/migrate and are applied with the rails db:migrate command.

A multiple select element allows selecting multiple objects. Rails' select helper in combination with the 'options_from_collection_for_select' helper can be used:

<%= form.select 'author_ids',
  options_from_collection_for_select(Author.all, :id, :name, paper.author_ids),
  {},
  multiple: true, size: 10 %>

Error

Expected to find css "select[multiple]" 1 time but there were no matches

Estimated progress: 94% complete