试图更新数据库 - 获取错误的参数数量错误?

时间:2015-01-11 15:47:17

标签: ruby-on-rails ruby ruby-on-rails-3

我在我的应用中添加了考勤跟踪功能,具备基本的时钟输入/输出时间

我为此行获得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>

2 个答案:

答案 0 :(得分:2)

where.not在Rails 4中引入

对于Rails 3,请使用

where('clock_in is not null') 

答案 1 :(得分:1)

您使用的是哪个版本的Rails?

在Rails 3.x中where.not未实现。