2016-08-03 77 views
0

未初始化不断在检查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 

回答

1

对不起,我分心了。我认为你的问题实际上是另一个问题,你必须在这里明确指定控制器和操作。 在一个侧面说明,也许你不得不改变你的魂在set_duel行动的参数的方式(我不记得是否导轨自动设置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 %> 
+0

我有一个'dueler '和'决斗'模型。 '决斗''has_many:应付者'。有没有一种方法可以让用户更新应用程序的'redirects_to'决斗显示页面? –

+0

render'duels/show',将编辑答案 – fabriciofreitag

+0

这给出了同样的错误作为问题:/澄清我试图做到这一点,而不创建一个“DuelersController”。感谢您的尝试! –