想知道是否可以使用带有活动管理员的默认值过滤?这对于为admin用户预加载数据很有帮助.
filter :country, :default=>'US'
Run Code Online (Sandbox Code Playgroud)
Fiv*_*ell 20
你可以通过定义before_filter来做到这一点
before_filter :only => [:index] do
if params['commit'].blank?
#country_contains or country_eq .. or depending of your filter type
params['q'] = {:country_eq => 'US'}
end
end
Run Code Online (Sandbox Code Playgroud)
UPD:
在某些情况下,如果params [:q]为空或params [:scope]为空,则需要设置过滤器
所以这可能会更好
before_filter :only => [:index] do
if params['commit'].blank? && params['q'].blank? && params[:scope].blank?
#country_contains or country_eq .. or depending of your filter type
params['q'] = {:country_eq => 'US'}
end
end
Run Code Online (Sandbox Code Playgroud)
改编的Fivells应用程序可以正确地使用范围和下载.感到hacky但似乎做了这个工作.评论中的注释意图.
before_filter only: :index do
# when arriving through top navigation
if params.keys == ["controller", "action"]
extra_params = {"q" => {"country_eq" => "US"}}
# make sure data is filtered and filters show correctly
params.merge! extra_params
# make sure downloads and scopes use the default filter
request.query_parameters.merge! extra_params
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5212 次 |
| 最近记录: |