我的控制器
new_task = {:user_id => params[:user_id],:task => params[:task] }
work = Work.new new_task
if work.valid?
work.save!
if !params[:sub].nil?
new_sub = {:activity => self.activity.id,:sub_task => "something etc" }
sub_task = SubTask.new new_sub
sub_task.save!
end
end
我的模特
attr_accessible :user_id, :task, :created_at, :updated_at
after_create :add_activity
def add_activity
new_activity = {:user_id => self.user_id,:text => "new task" }
user_activity = Activity.new new_activity
user_activity.save!
end
我如何获得活动表单 after_create 回调的最后插入 ID。self.activity.id 不适合我