这个答案更像是一个评论,但是很难理解这个问题是关于什么的,所以我决定把这个作为答案。
拜托,费尔南多,我们怎么知道你想做什么?表单应该提交到什么操作?您能否向我们展示您的 routes.rb,以便我们知道操作表单如何提交给您的控制器操作。也许,为了避免 Rails 中的命名约定问题,您应该将Action
Model 和 Controller重命名为Mission
or之类的名称Activity
。
你的params
哈希应该是什么样的?因为总会有一个 params[:action],在表单的情况下通常是create
or update
。
此外,请尝试使用内置的 rails 方法,例如:
# should be a POST method (am I right?)
# why do you call it viewTask?
def viewTask
@task = Task.find(params[:id])
# you'd better avoid extra DB-calls
# @status = @task.status
# @activities = @task.actions
# you can load this with the @task-query by including or joining them
# if you need the @status and @activities models you could do
# @task = Task.find(params[:id], :include => [:task, :activities])
# if you only need the joined objects you should use
@task = Task.find(params[:id], :joins => [:task, :activities])
@activity = Activity.new
if params[:activity]
@activity = @task.activities.build(params[:activity])
@activity.save
end
end
在代码中,我假设您的任务模型如下所示:
class Task < ActiveRecord::Base
has_many :activities
belongs_to :status # so it has a field called :status_id
.....
end