我使用了生成器腳手架的類別和問題。嵌套的路線form_for部分不適用於新的和編輯動作 - Rails 4
我的routes.rb
resources :categories do
resources :questions do
resources :choices, only: [:index]
end
end
當我嘗試添加或編輯一個問題會出現我的問題。
這裏是我的部分表格,之前你問關係的工作好吧。
<%= form_for [@question.category, @question] do |f| %>
<% if @question.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@question.errors.count, "error") %> prohibited this question from being saved:</h2>
<ul>
<% @question.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :question_type %><br>
<%= f.text_field :question_type %>
</div>
<div class="field">
<%= f.label :explanation %><br>
<%= f.text_field :explanation %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_field :description %>
</div>
<div class="field">
<%= f.label :category_id %><br>
<%= f.text_field :category_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我必須改變它的工作?現在我得到,
undefined method `questions_path'
你能證明你的'category'和'問題'模特? –
類別模型只有'has_many:questions',並且問題模型具有'belongs_to:category' –