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

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

@ -55,6 +55,18 @@ module RankKing
</tr>
<% end %>
</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
route do |r|
@ -76,10 +88,22 @@ module RankKing
end
r.on "axes" do
r.is Integer do |id|
r.on Integer do |id|
@axis = Axis[id]
view :axis
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
end
end
end
end

Loading…
Cancel
Save