路由错误:不存在的控制器的未初始化常量 [英] Routing Error: uninitialized constant for nonexistent controller

查看:108
本文介绍了路由错误:不存在的控制器的未初始化常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

duels/show.html.erb

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

There is no DuelersController only 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,如何将用户重定向回显示页面?

Once a user clicks submit how can I redirect the user back to the show page?

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):

Sorry, I was distracted. I think your problem is actually another, you have to explicitly specify the controller and action here. On a side note, maybe you'll have to change the way you fetch your parameters on the set_duel action (I don't remember if rails sets the id automatically), anyway:

#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 %>

这篇关于路由错误:不存在的控制器的未初始化常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆