Skip to content

Commit

Permalink
Refs #31: 5 author selections, wet, v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBrendel committed Nov 3, 2017
1 parent 88f82ca commit 61a9d8b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def update
@paper = Paper.find(params[:id])
@paper.authors = []
for i in 1..5
id = params.require(:paper)[('author' + i.to_s).to_sym]
id = params.require(:paper)[('author_' + i.to_s).to_sym]
@paper.authors << Author.find(id) if id && !id.to_s.empty?
end

Expand Down
10 changes: 5 additions & 5 deletions app/models/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ class Paper < ActiveRecord::Base
validates :year, numericality: { only_integer: true }
has_and_belongs_to_many :authors

def author1
def author_1
authors[0].id if authors[0]
end

def author2
def author_2
authors[1].id if authors[1]
end

def author3
def author_3
authors[2].id if authors[2]
end

def author4
def author_4
authors[3].id if authors[3]
end

def author5
def author_5
authors[4].id if authors[4]
end
end
10 changes: 5 additions & 5 deletions app/views/papers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
</p>

<%= f.label 'Author 1', for: 'paper_author_id_1' %><br>
<%= f.collection_select(:author1, Author.all, :id, :name, prompt: true) %><br>
<%= f.collection_select(:author_1, Author.all, :id, :name, prompt: true) %><br>
<%= f.label 'Author 2', for: 'paper_author_id_2' %><br>
<%= f.collection_select(:author2, Author.all, :id, :name, prompt: true) %><br>
<%= f.collection_select(:author_2, Author.all, :id, :name, prompt: true) %><br>
<%= f.label 'Author 3', for: 'paper_author_id_3' %><br>
<%= f.collection_select(:author3, Author.all, :id, :name, prompt: true) %><br>
<%= f.collection_select(:author_3, Author.all, :id, :name, prompt: true) %><br>
<%= f.label 'Author 4', for: 'paper_author_id_4' %><br>
<%= f.collection_select(:author4, Author.all, :id, :name, prompt: true) %><br>
<%= f.collection_select(:author_4, Author.all, :id, :name, prompt: true) %><br>
<%= f.label 'Author 5', for: 'paper_author_id_5' %><br>
<%= f.collection_select(:author5, Author.all, :id, :name, prompt: true) %>
<%= f.collection_select(:author_5, Author.all, :id, :name, prompt: true) %>

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

0 comments on commit 61a9d8b

Please sign in to comment.