0
我已經開始學習Ruby on Rails,並且我一直被困在某些東西中,需要您的幫助。要學習Rails,我正在構建一個創建,填寫和報告調查的應用程序。Rails應用程序需要幫助 - 查詢已執行,但數據不顯示
我的模型就像 - 每個調查都有很多問題,每個調查都有很多回應。每個迴應都有很多答案。
在我的報告頁面控制器,我做這樣的事情 -
def index
#@survey = Survey.find(params[:survey_id])
@user_responses = Response.where("survey_id = ?", params[:survey_id])
end
,並在視圖 -
<% @user_responses.each do |response| %>
Responder Name - <%= response.responder_name %><br/>
<% response.answers do |answer|%>
Question Id - <%= answerx.question_id %>
Answer - <%= answer.answer_text %>
<% end%>
<% end %>
我可以看到在後臺正在執行的查詢(由於環在視圖上),例如
[1m[36mResponse Load (0.3ms)[0m [1mSELECT "responses".* FROM "responses" WHERE (survey_id = '14')[0m
[1m[35mAnswer Load (0.3ms)[0m SELECT "answers".* FROM "answers" WHERE ("answers".response_id = 14)
[1m[36mAnswer Load (0.2ms)[0m [1mSELECT "answers".* FROM "answers" WHERE ("answers".response_id = 15)
但在視圖上,我無法看到「answer_text」/「question_id」。我只能看到「responder_name」
這與從視圖執行查詢有關嗎?
請幫幫我。
謝謝。
非常感謝,它的工作(愚蠢的我)。 – RockyJ 2010-11-15 07:20:17