- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我是 Ransack 的新手,我遇到了一个似乎没有被 Ransack 完全涵盖的案例。我基本上是在尝试搜索一个值,但搜索到的值包含在一个数组中。
<%= f.search_field :category_or_account_number_or_status_or_account_number_or_account_name_or_accounts_name_or_accounts_number_or_user_name_or_user_rep_code_list_cont_any %>
最后有一段 user_rep_code_list_cont
这是用户的默认数组属性,目前看起来像这样 ["al20", "b234"]
所以,当我在 Ransack 搜索栏中输入 al20 时,我得到了这个错误。
PG::UndefinedFunction: ERROR: operator does not exist: character
varying[] ~~* unknown
LINE 1: ..."name" ILIKE '%al20%') OR "users"."rep_code_list" ILIKE
'%al...
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.
def index
@q = Submission.submissions_for(user: current_user).ransack(params[:q])
@submissions = @q.result.includes(:user, :accounts).ordered(current_user).page(params[:page]).per(25)
end
同样,我不是 Ransack 专家,但这似乎是现在应该涵盖的内容。我想搜索数组模型的属性。
最佳答案
在这种情况下,我最终使用了自定义的 Ransacker
:
ransacker :rep_code_list do
Arel.sql("array_to_string(rep_code_list, ',')")
end
这会将数组转换为字符串,以便 Ransack 可以使用 cont
谓词进行搜索。不确定这是否是最好的方法,但它适用于我的情况。
关于ruby-on-rails - 使用 Ransack 搜索值数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49370841/
我正在尝试为我们的搜索页面创建一个 Ransack 部分,该部分将查看学生的成绩表并在每种成绩的范围内找到学生。 给定:Student has_many Grades and Grade belong
我有一个 Commodity(name:string) 模型和一个 Price(amount:float) 模型: class Commodity 我现在使用 prices.f
我是 Rails 的新手,非常感谢您的帮助和建议。 我目前正在使用 gem ransack 在我的架构中,我有一个名为 adverts 的表与列 title & content 我正在尝试通过一个链接
我有一个包含多个分类法的模型,使用 act-as-taggable-on class Film ['happy', 'snooze']}).result.count => 2 Film.sear
我正在使用 Spree,并且在它使用 Ransack 的产品/搜索 Controller 操作中。 Spree 文档说 Spree 没有提供自定义页面大小的方法,所以我想我应该自定义操作本身以使用 R
我正在使用 Ransack gem 和我有一个模型,它的范围是这样的: scope :by_attr, ->(attr) { case attr when val1 query1
我正在使用 Ransack Gem 并通过计数器缓存进行计数排序。我的属性是一个整数。 我这样称呼它: 我得到的排序输出是: [人升] 1 2 0 0 [人物描述] 0 0 2 1 我要 人事部显示
我正在尝试使用 Ransack gem,但它返回所有 12,000 行而不是使用过滤器。 Controller : def list @q = LmiHost.ransack(params[:q])
我有一个配方模型,该模型具有很多成分,每种成分都属于一个项目。在我的高级搜索表单中,我希望用户选择多种成分,然后让Ransack查找包含用户选择的所有成分的食谱。 我尝试了以下搜索字段: = f.co
我正在处理 ransack,我需要按创建年份(仅年份,而不是整个日期)进行排序。所以我在 Controller 中有这个: @q = Book.search(params[:q]) @q.sorts
将 Rails 2 应用程序转换为 Rails 3,我必须更换 gem searchlogic .现在,使用 Rails 3.2.8 和 gem Ransack我想构建一个使用现有范围的搜索表单。例子
我正在使用 Ransack 来提供数据过滤器。 主用户模型具有以下关联: user has_many trips, through registrations 基本搜索条件如user's name=x
如何从“开始日期”到“结束日期”进行搜索,然后对搜索结果后的列求和并进行搜索和分组? 我可以从开始日期搜索到结束日期,但我被困在必须求和和分组的地方 例如。历史.group(:name).sum(:p
我正在尝试为名为 Space 的对象创建一个搜索表单。我已经尝试使用很多 if 和 elsif,但我意识到它不起作用,所以我开始检查 Ransack。看起来很棒,如果能让它正常工作的话。 问题是,我的
我有一个使用 Ransack 构建的工作搜索表单,其中有两个单独的搜索字段用于两个不同的类,如下所示: 这些类中的每一个都链接到一个公司类 class Co
我在我的应用程序中使用 ransack gem 作为搜索机制。我面临的问题是,在我的模型中,我不小心将“日期”列创建为字符串字段,因此日期搜索不起作用,我无法根据日期进行比较。由于该列的数据类型是字符
我将搜索表单和搜索结果发布在同一页面上。 据我了解:搜查的默认设置是,如果提交的表单没有在搜索字段中输入任何值,则返回该特定资源的所有记录。 我该如何更改它,以便如果用户在搜索字段中未输入任何值的情况
我想使用 ransack 为包含 Users 的页面构建高级搜索功能。我有一个从出生日期计算年龄的小方法: def age(dob) now = Time.now.utc.to_date no
我有一个表,'jobs' 和一个枚举字段'status'。 status 具有以下枚举集: enum status: [ :draft, :active, :archived ] 使用 ransack
我必须使用 ransack 对数据库进行搜索。数据库中的一些列将数据存储在序列化数组中。我想将存储在数组中的确切数据与用户发送的数据进行匹配以执行搜索(用户的数据也是数组)。例如,在数据库中,一列数据
我是一名优秀的程序员,十分优秀!