ID當提交的答案,我得到這個錯誤:的Rails:Couldn`t找到#controller與
ActiveRecord::RecordNotFound (Couldn't find Question with ID=answer):
app/controllers/questions_controller.rb:6:in `show'
據我瞭解,我不是從形式或 didn`傳遞參數做了一個錯誤在我的控制器中正確定義它。
希望得到一些幫助找到這個bug,在此先感謝!
Questions_Controller:
class QuestionsController < ApplicationController
def index
end
def show
@question = Question.find(params[:id])
@choices = @question.choices
end
def answer
@choice = Choice.find(:first, :conditions => { :id => params[:id] })
@answer = Answer.create(:question_id => @choice.question_id, :choice_id => @choice.id)
if Question.last == @choice.question
render :action => "thank_you"
else
question = Question.find(:first, :conditions => { :position => (@choice.question.position + 1) })
redirect_to question_path(:id => question.id)
end
end
end
的意見/問題/ show.html.erb:
<div data-role="content">
<div align="center">
<h3><%= @question.question %></h3>
</div>
<br><br>
<ul data-role="listview">
<% @choices.each_with_index do |c, i| %>
<% i = i + 1 %>
<li data-theme="c">
<%= link_to "#{i}. #{c.choice}", answer_questions_path(:id => c.id) %>
</li>
<% end %>
</ul>
</div>
::編輯::
發生這種情況時,我嘗試選擇一個選項&提交第一個問題的答案。
Started GET "https://stackoverflow.com/questions/1" for 127.0.0.1 at Thu Dec 01 01:38:36 -0500 2011
Processing by QuestionsController#show as
Parameters: {"id"=>"1"}
SQL (0.6ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Question Load (0.3ms) SELECT "questions".* FROM "questions" WHERE "questions"."id" = 1 LIMIT 1
Choice Load (10.8ms) SELECT "choices".* FROM "choices" WHERE ("choices".question_id = 1)
Rendered questions/show.html.erb within layouts/application (28.8ms)
Completed 200 OK in 424ms (Views: 118.0ms | ActiveRecord: 11.6ms)
Started GET "https://stackoverflow.com/questions/answer?id=1" for 127.0.0.1 at Thu Dec 01 01:38:38 -0500 2011
Processing by QuestionsController#show as
Parameters: {"id"=>"answer"}
Question Load (0.1ms) SELECT "questions".* FROM "questions" WHERE "questions"."id" = 0 LIMIT 1
Completed in 10ms
ActiveRecord::RecordNotFound (Couldn't find Question with ID=answer):
app/controllers/questions_controller.rb:6:in `show'
希望這會有所幫助。
請描述你如何得到這個錯誤信息。 –
我發佈了一篇對原文的編輯,讓我知道是否還有其他我可以提供的內容。 –