我遇到了質量分配和強參數的問題。在我的模型中,我有幾個屬性,這些屬性是通過我的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