1

エラーが発生します:

引数の数が間違っています (1 に対して 2)

私のTaskモデルで、タスクのすべてのステータスを更新するメソッドを定義したとき。正しい構文は何ですか?

class Task < ActiveRecord::Base
  belongs_to :user

  def self.toggle(user, groups)
    groups.each do |status, ids|
      user.tasks.update_all({status: status.to_s}, {id: ids}) #=> error here
    end
  end
end

class GroupIdsByStatus
  def self.group(options = {})
    result = Hash.new {|h,k| h[k] = []} 
    options.reduce(result) do |buffer, (id, status)| 
      buffer[status.to_sym] << id
      buffer
    end
    result
  end
end

class TasksController < ApplicationController
  def toggle
    groups = GroupIdsByStatus.group(params[:tasks])
    Task.toggle(current_user, groups)

    redirect_to tasks_path
  end
end
4

1 に答える 1