尝试更新数据库 - 获取错误参数数量错误?
Trying to update database -- Get error wrong number of arguments?
我正在为我的应用程序添加考勤跟踪,具有基本的clock-in/clock-out能力
这一行我得到 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>
where.not
在Rails4
中介绍
对于Rails3,使用
where('clock_in is not null')
您使用哪个版本的Rails?
在Rails3.xwhere.not
中未实现。
我正在为我的应用程序添加考勤跟踪,具有基本的clock-in/clock-out能力
这一行我得到 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>
where.not
在Rails4
对于Rails3,使用
where('clock_in is not null')
您使用哪个版本的Rails?
在Rails3.xwhere.not
中未实现。