2014-02-21 91 views
0

我是rails新手,一直致力於創建一個基本的調查應用程序來處理嵌套資源。Rails link_to問題

這是我的最終數據結構應該是什麼樣子:

  1. 調查

  2. 問題,以及調查的外國

  3. 答案,有問題的外交

  4. 選擇,與正在參加調查的其他用戶和他將選擇的答案ID

我能夠創建調查和問題結構。但是我在回答中遇到了一些麻煩。它在我的問題的show.html.erb文件中的最後一行拋出一個錯誤,我試圖link_to我的新答案。

這裏的問題的show.html.erb文件:

<div id='question'> 
    <h2><%= @question.title %></h2> 
    <% if @question.single_response %> 
    <p>Single response</p> 
    <% else %> 
    <p>Multiple response</p> 
    <% end %> 
</div> 
<%= link_to "Edit Question", [:edit, @survey, @question] %> 
<%= link_to "Delete Question", [@survey, @question], method: :delete, data: { confirm: "Are you sure you want to delete this question?"} %> 

<p>Answers</p> 
<ul id='answers'> 
    <% @question.answers.each do |answer| %> 
    <li><%= link_to answer.title, [@survey, @question, answer] %></li> 
    <% end %> 
</ul> 
<p><%= link_to "Add Answer", new_survey_question_answer_path([@survey,@question]) %></p> 

這裏是我的routes.rb:

SurveyMe::Application.routes.draw do 

    resources :surveys do 
    resources :questions do 
     resources :answers 
    end 
    end 

    devise_for :developers 
    devise_for :users 

我敢肯定,這個問題是[@survey,@question]該行的一部分。任何想法我應該放在那裏?

這裏的錯誤:

Showing /Users/thomashammond89/Test Survey.me/app/views/questions/show.html.erb where line #18 raised: 

No route matches {:action=>"new", :controller=>"answers", :survey_id=>[#<Survey id: 2, title: "Test1", created_at: "2014-02-21 17:35:36", updated_at: "2014-02-21 17:35:36">, #<Question id: 2, title: "Question Test1", single_response: true, survey_id: 2, created_at: "2014-02-21 18:59:57", updated_at: "2014-02-21 18:59:57">], :id=>"2", :question_id=>nil, :format=>nil} missing required keys: [:question_id] 

Extracted source (around line #18): 

15 <li><%= link_to answer.title, [@survey, @question, answer] %></li> 
16 <% end %> 
17 </ul> 
18 <p><%= link_to "Add Answer", new_survey_question_answer_path([@survey,@question]) %></p> 
+0

您可以包括錯誤在你的問題? –

+0

我添加了錯誤。 H男子釘了它! –

回答

1

這應該是: new_survey_question_answer_path(@survey, @question)