Skip to content

Commit

Permalink
Refs #29: Allow author selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus-Brand committed Nov 9, 2017
1 parent 0dfa9a2 commit bfba496
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def create
def update
@paper = Paper.find(params[:id])

ids = params.require(:paper)[:author_ids]
@paper.authors = []
ids.each do |id|
@paper.authors << Author.find(id) unless id.to_s.blank?
end

if @paper.update(paper_params)
redirect_to @paper
else
Expand Down
8 changes: 8 additions & 0 deletions app/views/papers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<%= f.text_field :year %>
</p>

<p>
<% for i in 1..5 do%>
<% (istr = i.to_s) %>
<%= f.label ('Author ' + istr), for: ('paper_author_id_' + istr) %>
<%= f.collection_select(:author_ids, Author.all, :id, :name, {selected: @paper.author_ids[i - 1], include_blank: '(none)'}, {name: 'paper[author_ids][]', id: ('paper_author_id_' + istr)}) %>
<% end %>
</p>

<p>
<%= f.submit %>
</p>
Expand Down

0 comments on commit bfba496

Please sign in to comment.