-2
我想一个表的谁我smart_listing宝石
未知创建的内容过滤,SmartListing也被称为smart_listing
是一个Ruby宝石它提供一个工具,在您的Rails应用程序创建列表创建on Rails的筛选查询等方法,smart_listing宝石
我能使用分页,但过滤器仍然没有工作
Link to smart_listing documentation for Controls (filtering) documentation section
在文档说:
# Apply the search control filter.
# Note: `like` method here is not built-in Rails scope. You need to define it by yourself.
users_scope = users_scope.like(params[:filter]) if params[:filter]
这是我的代码,我怎么可以让运行过滤器?我有这样的控制器上
if !current_user.current_organization.import_columns.nil?
@import_contacts = UserImport.where(organization_id: current_user.current_organization.id)
@import_contacts_column_filter = current_user.current_organization.import_columns.split(/,/)
contacts_import_scope = @import_contacts
contacts_import_scope = contacts_import_scope.like(params[:filter]) if params[:filter]
#contacts_import_scope = begin_of_association_chain.order('active DESC')
#contacts_import_scope = contacts_import_scope.imported_users_filter(params[:filter].strip) if params[:filter]
@import_contacts_listing = smart_listing_create(
:import_contacts,
contacts_import_scope,
partial: 'contacts/listing_import',
default_sort: {created_at: "desc"}
)
end
这对意见
index.html.slim
.tab-content
- if @import_contacts.any?
.search-wrapper.pull-right
= smart_listing_controls_for(:import_contacts) do
span.btn.pull-right
i.fa.fa-search
.filter.input-append.pull-right
= text_field_tag :filter, '', class: 'search', placeholder: "#{t('commons.filters.search_pending_petition_contacts')}", autocomplete: 'off'
_listing_import.slim
- unless smart_listing.empty?
.pending_contacts_table.table-responsive
table class="table-striped table-list" style="width: 100%; background-color: #FAFBFD;"
thead
tr
- @import_contacts_column_filter.each do |column|
th.name.col-sm-2 = smart_listing.sortable "#{column}", "#{column}"
th.name.col-sm-2 Añadir
tbody
- smart_listing.collection.each do |user_imported|
tr
- @import_contacts_column_filter.each do |field|
td = "#{user_imported.send(field)}"
td
- if User.exists?(email: user_imported.email)
p Ya añadido
- else
- last_name = "#{user_imported.surname1}"+"#{user_imported.surname2}"
= link_to new_organization_customer_path(name: user_imported.name, last_name: last_name, email: user_imported.email, tmp_pass: user_imported.tmp_pass), class: 'btn btn-success' do
i class='fa fa-plus-square'
= page_entries_info smart_listing.collection
= smart_listing.paginate
- else
我们如何定义文档的.like
方法?
正如我写的代码,并留下评论,在我试图用这种方式写也没有结果。
#contacts_import_scope = contacts_import_scope.imported_users_filter(params[:filter].strip) if params[:filter]