Rails为Filterrific设置了错误的参数数量(给定2,预期为1)

时间:2016-10-06 16:21:16

标签: ruby-on-rails activerecord filterrific

我正在使用Filterrific gem尝试按月和年排序事件,但是我收到以下错误:

ArgumentError at /events
wrong number of arguments (given 2, expected 1)

相关代码:

# models/event.rb

class Event < ApplicationRecord
  belongs_to :venue
  belongs_to :performer

  filterrific(
    default_filter_params: { sorted_by: 'created_at_desc' },
    available_filters: [
      :sorted_by,
      :search_query,
      :with_venue_id,
      :with_performer_id,
      :with_year_and_month
    ]
  )

  scope :with_year_and_month, lambda { |reference|
    where(date: reference..reference.next_month)
  }

  def self.options_for_select
    order('LOWER(name)').map { |e| [e.date.strftime("%Y-%m-%d"), e.date.strftime("%Y-%m-1")] }
  end
end


# controllers/events_controller.rb

class EventsController < ApplicationController
  def index
    @filterrific = initialize_filterrific(
      Event,
      params[:filterrific],
      select_options: {
        sorted_by: Event.options_for_sorted_by,
        with_venue_id: Venue.options_for_select,
        with_performer_id: Performer.options_for_select,
        with_year_and_month: Event.options_for_select
      }
    ) or return
    @events = @filterrific.find.page(params[:page])

    respond_to do |format|
      format.html
      format.js
    end
  end
end

我感到困惑,因为我的Venue模型中的格式相同,并且它们似乎都传递了相同数量的参数:

# models/venue.rb

class Venue < ApplicationRecord
  has_many :events

  def self.options_for_select
    order('LOWER(name)').map { |e| [e.name, e.id] }
  end
end

0 个答案:

没有答案