我遇到了质量分配和强参数的问题。在我的模型中,我有几个属性,这些属性是通过我的mysql数据库中的一列表示的。我也有一个领域,那不是。我只需要它来计算一个值。我不想将它存储在我的数据库中。Rails4没有数据库列的强参数
在我的控制,我定义的强参数:
def timeslots_params
params.require(:timeslot).permit(:employee_id, :dienstplan_id, :start_date, :start_time)
end
但是当我试图访问START_TIME属性在我的控制,我发现了
undefined method `start_time' for #<Timeslot:0x007fff2d5d8070> error.
定义的其他带有db列的参数存在并填充值。我是否错误理解强参数并且必须定义其他内容?
编辑:这里是代码,在那里我称之为timeslots_params:
def create
@e = Timeslot.new(timeslots_params)
@e.start_date = @e.start_date.to_s + " " + @e.start_time.to_s
if @e.save
current_user.timeslots << @e
respond_to do |format|
format.json { render :json => @e }
end
end
end
你可以发布'Timeslot'模型类的代码和你在那里定义'start_time'的地方吗? – Surya 2014-10-28 17:33:29
发布您正在调用'timeslots_params'的行为并获取该错误。 – nikkon226 2014-10-28 18:24:28
我已将代码添加到我的第一篇文章中 – user39063 2014-10-28 18:39:19