我一直在试图通过控制台保存一些信息。我能更新条目,但是当我继续前进,并尝试将其保存,我得到以下错误:由于current_user而无法从控制台保存问题NoMethodError
NoMethodError: undefined method `current_user' for nil:NilClass
我最初的反应是,我需要“登录”的用户,但控制台应该不需要这个(除非我错了)。我目前在我的本地服务器上,仍然遇到此问题。前段时间我能够完成这种类型的行动,但现在它不允许我。这是一个很大的问题,因为我需要使用控制台为管理和/或故障排除目的手动更新条目。
只是为了提供一个例子我目前的架构(可能会或可能不会有帮助/相关):
2.1.1 :022 > task = Task.find(16)
Task Load (0.2ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ? ORDER BY importance DESC, priority DESC, duedate, updated_at LIMIT 1 [["id", 16]]
=> #<Task id: 16, description: "new tasks", done: false, project_id: 8, created_at: nil, updated_at: nil, due: nil, started: true, active: nil, repeat: nil, time_limit: nil, priority: nil, assignee: "", creator: "[email protected]", started_at: nil, completed_at: nil, paused_at: nil, resumed_at: nil, time_spent: nil, accepted: nil, duedate: nil, duetime: nil, repeat_time: nil, repeat_day: nil, repeat_date: nil, repeat_ordinal: nil, importance: "">
2.1.1 :023 > task.started_at = DateTime.now
=> Mon, 14 Jul 2014 12:02:47 -0700
2.1.1 :024 > task.save
(0.8ms) begin transaction
SQL (1.3ms) UPDATE "tasks" SET "started_at" = ?, "updated_at" = ? WHERE "tasks"."id" = 16 [["started_at", "2014-07-14 12:02:47.458736"], ["updated_at", "2014-07-14 12:02:49.949408"]]
(1.1ms) rollback transaction
NoMethodError: undefined method `current_user' for nil:NilClass
我明白任何帮助任何人都可以提供。提前致谢。
任务模式:
class Task < ActiveRecord::Base
belongs_to :project
validates :description, presence: true
default_scope { order('importance DESC', 'priority DESC', 'duedate','updated_at') }
include PublicActivity::Model
tracked owner: Proc.new{ |controller, model| controller.current_user }
end
请发布您的任务模型的代码 – infused