我在routes.rb中有这些资源。主题下的评论。
namespace :discuss do
resources :topics, :as => :topic do
resources :comments, :as => :comment
end
end
并拥有_form.html.erb
<%= form_for(@topic) do |f| %>
<div class="field">
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
渲染此表单时出错 未定义的方法`topics_path'for ... 在&lt;%= form_for(@topic)附近执行| f | %GT;
rake routes
discuss_topic_comment_index GET /discuss/topics/:topic_id/comments(.:format) discuss/comments#index
POST /discuss/topics/:topic_id/comments(.:format) discuss/comments#create
new_discuss_topic_comment GET /discuss/topics/:topic_id/comments/new(.:format) discuss/comments#new
edit_discuss_topic_comment GET /discuss/topics/:topic_id/comments/:id/edit(.:format) discuss/comments#edit
discuss_topic_comment GET /discuss/topics/:topic_id/comments/:id(.:format) discuss/comments#show
PUT /discuss/topics/:topic_id/comments/:id(.:format) discuss/comments#update
DELETE /discuss/topics/:topic_id/comments/:id(.:format) discuss/comments#destroy
discuss_topic_index GET /discuss/topics(.:format) discuss/topics#index
POST /discuss/topics(.:format) discuss/topics#create
new_discuss_topic GET /discuss/topics/new(.:format) discuss/topics#new
edit_discuss_topic GET /discuss/topics/:id/edit(.:format) discuss/topics#edit
discuss_topic GET /discuss/topics/:id(.:format) discuss/topics#show
PUT /discuss/topics/:id(.:format) discuss/topics#update
DELETE /discuss/topics/:id(.:format) discuss/topics#destroy
discuss /discuss(.:format)
我的控制器app / controllers / discuss / topics_controller.rb
module Discuss
class TopicsController < ApplicationController
def new
@topic = Topic.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @topic }
end
end
... some other actions ...
end
end
我对这张表格做错了什么?
答案 0 :(得分:0)
尝试替换:
<%= form_for(@topic) do |f| %>
使用:
<%= form_for [:discuss, @topic] do |f| %>