Routing Error: uninitialized constant for nonexistent controller

╄→гoц情女王★ 提交于 2020-01-06 14:30:47

问题


Upon checking submit I get 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 %>

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

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

回答1:


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


来源:https://stackoverflow.com/questions/38753687/routing-error-uninitialized-constant-for-nonexistent-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!