问题
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