所以我认为由于下面的代码而遗漏了一些东西,我已经包含了错误消息,我认为任务表没有 task_id,但是当我运行迁移以将 task_id 添加到任务时,它仍然给了我这个错误。
路线
resources :tasks do
resources :comment
end
模型 - 评论
class Comment < ActiveRecord::Base
attr_accessible :author, :comment
belongs_to :tasks
has_one :author
validates :comment, :presence => true
end
模型任务
class Task < ActiveRecord::Base
attr_accessible :name, :task
has_many :comments, :dependent => :destroy
validates :name, :presence => true
end
评论控制器
class CommentsController < ApplicationController
def index
@comment = Comment.new
@comments = Comment.all
end
def create
@task = Task.find(params[:id])
@comment = @task.Comment.create(params[:task])
redirect_to post_path(@task)
end
end
形式 - 部分
<%= form_for ([@task, @task.comments.build]) do |f| %>
<%= f.text_area :comment %>
<%= f.submit %>
<% end %>
什么问题?
unknown attribute: task_id
Extracted source (around line #1):
1: <%= form_for ([@task, @task.comments.build]) do |f| %>
2: <%= f.text_area :comment %>
3: <%= f.submit %>
4: <% end %>
Trace of template inclusion: app/views/tasks/show.html.erb
Rails.root: /home/adam/Documents/Aptana Studio 3 Workspace/StartPoint
Application Trace | Framework Trace | Full Trace
app/views/forms/_comments.html.erb:1:in `_app_views_forms__comments_html_erb___445541804__622889658'
app/views/tasks/show.html.erb:5:in `_app_views_tasks_show_html_erb___428009053_87363420'
Request
Parameters:
{"id"=>"3"}