我有一个自定义列表,我从“后台”创建,我在其中添加要从数据库表中检索的列。这成了一个数组。好吧,我想从与Id匹配的行中只检索那些列。
这是我的代码:
def load_import_contacts
@import_contacts_column_filter = current_user.current_organization.import_columns.split(/,/) # the "custom filter" that retrieve columns
@import_contacts = UserImport.select(@import_contacts_column_filter).where(organization_id: current_user.current_organization.id) # the query
# here all ok, objects filtered how i want.
@import_contacts_listing = smart_listing_create(
# here comes the error message
:import_contacts,
@import_contacts,
partial: 'contacts/listing_import',
default_sort: {created_at: "desc"}
)
end
错误消息:
标题
ActiveRecord::StatementInvalid in ImportsController#index
正文消息
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' name, surname1, surname2, phone, adress, city, zipcode, zone, birthdate, firstv' at line 1: SELECT COUNT(reference_number, name, surname1, surname2, phone, adress, city, zipcode, zone, birthdate, firstvisit, mutua, organization_id) FROM `user_imports` WHERE `user_imports`.`organization_id` = 279
更多详情
Extracted source (around line #15):
第15行:
@import_contacts_listing = smart_listing_create(
答案 0 :(得分:0)
奇怪的解决方案:
当我在智能列表之前添加此行
**@import_contacts.each do |before|
end**
一切运行正常,很奇怪,我不知道为什么会这样。