私はすべてのユーザとその属性id、name、age、status、locationを表示するシンプルなテーブルを持っています。私は年齢と状態をフィルタリングしたいフィルタを適用した後にビューが更新されない[ruby rails filterrific]
Id name age status location
1 xz 22 single ca
2 yy 23 married ma
私はfilterrificプラグインを使用して、リストとフィルタードロップダウンを表示することができています。
マイuser.rb
filterrific(
available_filters: [
:with_status,
:with_age
]
)
scope :with_age, lambda { |age|
where(age: [*age])
}
scope :with_status, lambda { |status|
where(status: [*status])
}
def self.options_for_select
order('LOWER(status)').map { |e| [e.status] }.uniq
end
def self.options_for_select2
order('LOWER(age)').map { |e| [e.age] }.uniq
end
コントローラインデックスは
def index
@filterrific = initialize_filterrific(
User,
params[:filterrific],
select_options: {
with_status: User.options_for_select,
with_clearance_batch_id: User.options_for_select2
},
default_filter_params: {},
available_filters: [],
) or return
@users = @filterrific.find
respond_to do |format|
format.html
format.js
end
end
のように見えます私は私がページに移動するとindex.html.erbは
<%= form_for_filterrific @filterrific do |f| %>
<div>
age
<%= f.select(
:with_age,
@filterrific.select_options[:with_age],
{ include_blank: '- Any -' },
{class: 'form-control' }
) %>
</div>
<div>
status
<%= f.select(
:with_status,
@filterrific.select_options[:with_status],
{ include_blank: '- Any -' },
) %>
</div>
<% end %>
<%= render(
partial: 'browse_users/list',
locals: { users: @users }
) %>
のように見えますすべてのユーザーを見ることができます。今私は何もフィルターをかけることはありません。私はまだすべてのユーザーを参照してください。何が起こっているのか分かりません。スコープフィルタが適用されていないと感じています。私に