在rails 4中设置date_range的默认值

时间:2016-09-09 21:30:24

标签: ruby-on-rails

如何在rails 4中设置默认值。我正在尝试

filter :by_resolved_at_in, as: :date_range,label: "Filtro Resolvido em", :value => Time.now.strftime('%Y-%m-%d')

1 个答案:

答案 0 :(得分:0)

这是ActiveAdmin,对吧?

您无法在filter行中执行此操作,但可以定义一个before_filter,其中初始化了搜索范围。

  before_filter :only => [:index] do
    if params['commit'].blank?
       params['q'] = {by_resolved_at_in: Date.today..Date.today} 
    end
  end