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