我正在通过嵌套形式创建一个孩子,并且我知道这些路线有效,因为我在上面。
resources :surveys do
resources :questions
end
我也选择了第一个调查来添加问题,然后我想在页面上显示调查的名称:
class QuestionsController < ApplicationController
def new
@Survey = Survey.find(params[:id])
@question = Question.new
end
end
http://localhost:3000/surveys/1/questions/new
<div><%= @survey.name %></div> # show this
<div>
<%= simple_form_for(@question do |f| %>
<%= f.button :submit, "Done" %>
<% end %>
</div>
这给了我错误:
ActiveRecord::RecordNotFound in SurveysController#new
Couldn't find Survey without an ID
app/controllers/questions_controller.rb:7:in `new'
{"survey_id"=>"1"}
为什么?这里发生了什么?