Routing Error: uninitialized constant for nonexistent controller

Routing Error: uninitialized constant for nonexistent controller

检查 submit 我得到 Routing Error: uninitialized constant DuelersController

duels/show.html.erb

The loser(s) will <%= @duel.consequence %><br><br>
If everyone succeeds they will <%= @duel.reward %>
<%= form_for @dueler do |f| %>
  Accept? <%= f.check_box :accept %>
  <%= f.submit %>
<% end %>

没有DuelersController只有DuelsController

def show
  @dueler = Dueler.find_by(user_id: current_user.id)
  respond_with(@duel)
end

def set_duel
  @duel = Duel.find(params[:id])
end

一旦 user 点击 submit 我如何将用户重定向回显示页面?

Dueler.last
 id: 20,
 user_id: 78,
 challenge_id: 178,
 duel_id: 13,
 accept: nil> # For example redirect back to duels/13 with accept: true

对不起,我走神了。我认为您的问题实际上是另一个问题,您必须在此处明确指定控制器和操作。 在旁注中,也许您必须更改在 set_duel 操作中获取参数的方式(我不记得 rails 是否自动设置了 id),无论如何:

#Assuming you want to call set_duel upon submission
<%= form_for @dueler, :url => { :controller => "duel", :action => "set_duel" }, :html => {:method => :post} do |f| %>
  Accept? <%= f.check_box :accept %>
  <%= f.submit %>
<% end %>