0
我加入考勤跟蹤到我的應用程序,基本時鐘輸入/時鐘輸出能力試圖更新數據庫 - 獲取錯誤的錯誤數量的參數?
我得到wrong number of arguments (0 for 1)
這條線:
scope :running, -> { where(clock_out: nil).where.not(clock_in: nil) }
這是我有:
控制器:
class AttendenceRecordsController < ApplicationController
def clock_in
@clock_in = current_user.attendence_records.create(clock_in: DateTime.current)
respond_to do |format|
if @clock_in.save
format.html { redirect_to root_path, notice: "You've clocked in successfully" }
else
format.html { redirect_to root_path, notice: "Something went wrong, you were not clocked in" }
end
end
end
def clock_out
current_user.attendence_records.running.first.finish!
respond_to do |format|
format.html { redirect_to root_path, notice: "You've clocked out successfully" }
end
end
end
型號條
class AttendenceRecord < ActiveRecord::Base
belongs_to :users
scope :running, -> { where(clock_out: nil).where.not(clock_in: nil) }
def finish!
update(clock_out: DateTime.current)
end
end
路線
Mysupport::Application.routes.draw do
put "attendence_records/clock_in", to: "attendence_records#clock_in", as: :attendence_clock_in
put "attendence_records/clock_out", to: "attendence_records#clock_out", as: :attendence_clock_out
end
查看
<ul class="dropdown-menu">
<li><%= link_to "Clock In", attendence_clock_in_path, method: :put %></li>
<li><%= link_to "Clock Out", attendence_clock_out_path, method: :put %</li>
</ul>
它工作。但是,它不更新數據庫記錄?我在控制器上做錯了什麼? – meritonch
@meritonch你可能應該使用'update_attributes({clock_out:DateTime.current})',如果你想查看錯誤,把'!'放在最後,比如'update!(clock_out:DateTime.current)'。 'update'是Rails 4 –
中'update_attributes'的別名,是的,我想通了,謝謝! ....現在一切都很好。 ...你想引導我創建報告和報告視圖的任何方向? – meritonch