如何将另一个参数传递给方法?

时间:2018-09-06 08:12:14

标签: ruby-on-rails ruby-on-rails-5

更新

我如何通过该方法转移交易对手,以便除了年份和月份外,还会转移他?

  scope :extract_by_date, -> (props) {
    if props[:months].present?
      extract_by(:year, props[:years]).extract_by(:month, props[:months])
    else
      extract_by(:year, props[:years])
    end
  }

我想我需要添加类似的内容,但是它不起作用,请帮忙。

extract_by(:year, props[:years]).extract_by(:month, props[:months]).extract_by(:counterparty, props[:counterparty])) 

filters.js(React / Redux)

render() {
  const { filter, current, handleFilterChange } = this.props;
  const monthsNames = moment.monthsShort();
  const options = {
    years: filter.years.map((year) => {
      return { value: year, label: year };
    }),
    months: monthsNames.map((monthName, index) => {
      return { value: index + 1, label: monthName };
   })
}

和 conroller.rb

  def index
    props = {
      years: params[:year],
      months: params[:month]
    }

    unless props_valid?(props)
      return render_api({ years: registers.years }, :ok)
    end

    items = registers.extract_by_date(props).by_page(params[:page]).order(created_at: :desc) 
    render_api({ items: items, years: registers.years, counterparty: counterparty },
                 :ok, each_serializer: RegistersSerializer)
  end

我需要更改控制器和模型,以便它们将数据传输到反应文件。

0 个答案:

没有答案