Tag: 在哪里

使用OR和AND搜索多个列以应用filter

我正在开发一款应用。 我试图植入一个搜索系统。 方法很简单。 在家里,我在3栏“name”或“nomdep”或“nomregion”上搜索查询。 在此之后,我想用AND运算符用params过滤。 如果我只使用一列植入搜索,例如“NAME”,那么我可以应用filter。 但如果我想用多个OR植入这个,我不能应用filter。 我认为OR运算符是问题所在。 但我肯定不知道要解决这个问题…… 你能帮助我吗 ? 谢谢 camping.rb has_many :caracteristiquetests, :foreign_key => :camping_id has_many :situations, :foreign_key => :camping_id def self.searchi(query, handicap, animaux, television, plage, etang, lac) return scoped unless query.present? left_outer_joins(:caracteristiquetests, :situations).where([‘nomdep LIKE ? OR name LIKE ? OR nomregion LIKE ? AND handicap LIKE ? AND animaux LIKE ? […]

通过深入了解关系来获得数量

我正在使用Rails 4,我希望获得针对特定post的每个post评论的计票数。 架构: Post PostReview PostReviewVote id post_id post_review_id user_id user_id voted_on_date 我有类似的东西: table.table.table-striped.table-hover thead tr th Post Name th Reviews Created For Post th Total Votes in All Reviews For Post tbody – for post in @posts tr td= post.name td= PostReview.where(post_id: post.id).size td= PostReview.where(post_id: post.id).PostReviewVotes.size 但它并没有提取,引用了运行时错误: undefined method `PostReviewVotes’ for # 有什么建议? 我的模型有适当的关联,仅供参考。

Rails ActiveRecord where或clause

我正在寻找一个ActiveRecord查询,这就是我在下面的内容。 不幸的是你不能像这样使用OR。 什么是最好的执行方式? category_ids是一个整数数组。 .where(:”categories.id” => category_ids).or.where(:”category_relationships.category_id” => category_ids)

Rails – 如何在searchkick中为filter添加更多字段?

在rails中,我使用searchkick gem进行搜索。 当我为where子句添加更多字段时,返回零结果。 实际上搜索正在下面的方法(User.rb), searchkick word_start: [:name] def initialize(name, limit = User::SUGGESTION_LIMIT, page = nil) @name = name @limit = limit @page = page @per_page = limit.to_i end query = { match: :word_start, fields: [{ emails: “exact” }, “name^5”], misspellings: { prefix_length: 2 }, load: false } User.search(name, query).records 当我添加条件时,如where: {active: false, inactive: true, deleted_at: […]

Rails – 如何在searchkick中过滤字符串字段?

在rails中,我使用searchkick gem进行搜索。 我需要为filter添加一个名为status字符串字段。 我该如何添加到这个插件? 我已经提出了一个关于这个问题的问题Rails – 如何在searchkick中为filter添加更多字段? 现在我尝试使用字符串字段而不是布尔值仍然搜索不起作用。 请帮我一下。 我添加了一个条件,例如where: {status: ‘approved’} ,根据这个条件,我应该只获得活跃用户(不是’已删除’用户)。 现在没有显示搜索数据。 searchkick word_start: [:name] def initialize(name, limit = User::SUGGESTION_LIMIT, page = nil) @name = name @limit = limit @page = page @per_page = limit.to_i end query = { match: :word_start, where: {status: ‘approved’}, fields: [{ emails: “exact” }, “name^5”], misspellings: { prefix_length: […]

Rails 3使用NOT NULL在.where条件之后排序

我有一个显示最快用户的排名: @users = User.find.sort { |a, b| b.finished_at a.created_at } 现在我要添加一些代码以防止因为finished_at beeing nil而导致错误,直到用户完成。 @users = User.find(:all, :conditions => “finished_at IS NOT NULL”).sort { |a, b| b.finished_at a.created_at } 但sort不起作用。 这种链接方法有缺陷吗? 并且find(:all, :conditions => “finished_at IS NOT NULL”) rails 3路还是过时的? 提前致谢