使用设备的任务,不能创建任务 我的模型 用户无法创建色器件
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :tasks
end
任务
class Task < ApplicationRecord
belongs_to :user
end
任务控制器
def create
@task = Task.new(task_params)
respond_to do |format|
if @task.save
format.html { redirect_to @task, notice: 'Task was successfully created.' }
format.json { render :show, status: :created, location: @task }
else
format.html { render :new }
format.json { render json: @task.errors, status: :unprocessable_entity }
end
end
end
,并试图在创建任务有错误
1错误禁止被保存在这个任务:
User must exist
我的反应
开始POST “/任务” 为127.0.0.1,在2017年12月27日14时20分59秒0200 处理由TasksController#创建以HTML 参数:{ “UTF8”=> “✓”, “authenticity_token”=> “b7EkQsJygYBW1xLIm1uFD8jluXy2LYeoYjAOjKcwWOMHLwtalXmkTrNJu0yhexucwY94COegDcuVrOWLRkf8dg ==”, “任务”=> { “标题”=> “”,“描述“=>”“,”优先“=>”“,”due(1i)“=>”2017“,”due(2i)“=>”12“,”due(3i)“=>”27“ ,“完成”=>“0”},“提交”=>“创建任务”}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
(0.0ms) begin transaction
(0.1ms) rollback transaction
怎么了?
它的工作原理,但不是正确的。当我添加到new_task_view