Alpha Chen 1 year ago
parent 493a2fb88c
commit 8bfd17db38
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -35,7 +35,7 @@ module RankKing
class Ranking < Sequel::Model class Ranking < Sequel::Model
many_to_one :axis many_to_one :axis
many_to_one :winner, class: :Item many_to_one :winner, class: "RankKing::Item"
many_to_one :loser, class: :Item many_to_one :loser, class: "RankKing::Item"
end end
end end

@ -55,6 +55,18 @@ module RankKing
</tr> </tr>
<% end %> <% end %>
</table> </table>
<ul>
<% @game.each do |item| %>
<li><%= item.title %></li>
<% end %>
</ul>
<form method="post" action="/pools/<%= @pool.id %>/axes/<%= @axis.id %>/rank">
<% @game.each.with_index do |item, i| %>
<label><input type="radio" name="winner" value="<%= item.id %>"><%= item.title %></label>
<input type="hidden" name="item_<%= i %>" value="<%= item.id %>">
<% end %>
<input type="submit">
</form>
ERB ERB
route do |r| route do |r|
@ -76,9 +88,20 @@ module RankKing
end end
r.on "axes" do r.on "axes" do
r.is Integer do |id| r.on Integer do |id|
@axis = Axis[id] @axis = Axis[id]
r.is "rank" do
items = r.params.values_at("item_0", "item_1").map { Item[_1] }
winner, loser = items.partition { _1.id == r.params.fetch("winner").to_i }.flatten
RankKing.rank(@axis, winner:, loser:)
r.redirect "/pools/#{@pool.id}/axes/#{@axis.id}"
end
r.is do
@game = RankKing.suggest_game(@axis).shuffle
view :axis view :axis
end end
end end
@ -86,4 +109,5 @@ module RankKing
end end
end end
end end
end
end end

Loading…
Cancel
Save