检查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
答案 0 :(得分:1)
抱歉,我分心了。我认为你的问题实际上是另一个,你必须在这里明确指定控制器和动作。 另外,也许你必须改变你在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 %>