我有一个带有名为"map_id"的整数列的表,我想添加一个activeadmin过滤器来过滤此列是否为NULL或IS NOT NULL.
怎么能实现呢?
我尝试了以下过滤器
filter :map_id, :label => 'Assigned', :as => :select, :collection => {:true => nil, :false => ''}
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误消息:
用于#的未定义方法`map_eq'
我认为这个问题不够明确; 这是一个直接更新的问题点:
构建元搜索引擎时使用的常见体系结构是什么?是否有可用于构建此类搜索引擎的库?
我正在寻找构建"企业"类型的搜索引擎,其中索引数据可能来自专有(如Autonomy或Google Box)或公共搜索引擎(如Google Web或Yahoo Web).
我正在使用meta_search对表中的列进行排序.我的一个表列是特定模型的相关记录的计数.
基本上是这样的:
class Shop < ActiveRecord::Base
has_many :inventory_records
def current_inventory_count
inventory_records.where(:current => true).count
end
end
class InventoryRecord < ActiveRecord::Base
belongs_to :shop
#has a "current" boolean on this which I want to filter by as well
end
Run Code Online (Sandbox Code Playgroud)
在我的Shop #index视图中,我有一个表格列出了每个商店的current_inventory_count.无论如何使用meta_search按此计数订购商店?
我无法使用current_inventory_count方法,因为meta_search只能使用返回ActiveRecord :: Relation类型的自定义方法.
我能想到这样做的唯一方法是做一些自定义SQL,其中包括"虚拟"列中的计数,并按此列进行排序.我不确定这是否可能.
有任何想法吗?
我正在使用Rails 3.0.3和最新的meta_search.
我有两个模型之间的belongs_to和has_many assotiations.默认情况下,activeadmin使用select输入.但就我而言,这是不可能的 - 因为我有成千上万的物品.当我尝试更改过滤器时
filter :item, as: :string
Run Code Online (Sandbox Code Playgroud)
它说
undefined method `item_id_contains' for #<MetaSearch::Searches::DeliveryTime:0x007fdd57f12db8>
Run Code Online (Sandbox Code Playgroud)
做正确的最佳方法是什么?
我有一个Rails 3应用程序,其中我的模型包括所有者和属性,每个所有者代表拥有一个或多个属性的个人或机构.
我希望能够搜索我的数据库(SQLite3)并返回按所有者分组的结果.对于每个组,我想显示:
- 所有者的名字(我可以轻松地做到这一点) - 属于该所有者的属性总数,满足搜索条件(即计数). - 前一列中计算的所有属性的总值(即总和).
所有者has_many属性,属性belongs_to所有者.此外,"value"是Property的属性.
我正在使用MetaSearch gem,我可以让它正确返回一组属性.我也可以让它按照所有者对结果进行分组,但我无法弄清楚如何显示属性数量及其总和值.
以下是返回属性列表的代码:
@search = Property.group("owner_id").search(params[:search])
Run Code Online (Sandbox Code Playgroud)
我试过像这样在链中添加一个.select:
@search = Property.select("SUM(value) as mysum").group("owner_id").search(params[:search])
Run Code Online (Sandbox Code Playgroud)
但是当我尝试时,我无法获得这笔钱.有谁知道处理这种情况的有效方法?
我已经使用地理编码器实现了基于位置的搜索,并且在集成meta_search gem时遇到了问题.我正在尝试将meta_search集成到我的内容中,object_controller index以允许用户在:attributes按位置搜索后按对象对搜索结果进行过滤和排序.
我的object_controller:
def index
if params[:search].present?
@objects = Object.near(params[:search], 50, :order => :distance).paginate(:page => params[:page], :per_page => 9)
else
@objects = Object.paginate(:page => params[:page], :per_page => 9)
end
end
Run Code Online (Sandbox Code Playgroud)
知道如何最好地将@search集成到meta_search gem所需的索引中吗?
以下是meta_search github为索引推荐的内容:
def index
@search = Article.search(params[:search])
@articles = @search.all # load all matching records
# @articles = @search.relation # Retrieve the relation, to lazy-load in view
# @articles = @search.paginate(:page => params[:page]) # Who doesn't love will_paginate?
end
Run Code Online (Sandbox Code Playgroud)
非常感谢,
将
在将Rails 3.2项目部署到Weblogic 10.3时遇到此问题,并且正在寻找一个简单的答案.
org.jruby.exceptions.RaiseException: (NameError) ActiveRecord is not missing constant Base!
at RUBY.load_missing_constant(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:494)
at RUBY.const_missing(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
at RUBY.const_missing(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/meta_search-1.1.3/lib/meta_search.rb:55)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at ActiveSupport::Dependencies::Loadable.load_dependency(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/active_admin.rb:1)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at ActiveSupport::Dependencies::Loadable.load_dependency(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236)
at ActiveSupport::Dependencies::Loadable.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/active_admin.rb:1)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/activeadmin.rb:1)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/activeadmin-0.5.0/lib/activeadmin.rb:1)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:1)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:68)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:66)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler/runtime.rb:55)
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at RUBY.require(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/gems/gems/bundler-1.2.3/lib/bundler.rb:128)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/config/application.rb:13)
at RUBY.(root)(<app_deploy_dir>/<app_name>/mfey8c/war/WEB-INF/config/environment.rb:1)
Run Code Online (Sandbox Code Playgroud)
环境看起来像这样:JRuby 1.7.2,JRockit 1.6,Rails 3.2.9,Warbler
我部署了基本的2模型加设计用户项目,当我在浏览器中浏览它时会发生此错误.谁看过这个吗?这是我第一次使用JRuby.
编辑:
添加我最近的失败尝试.请注意,我已经尝试过jruby,jruby-jar,分别为1.6.8,1.7.0,1.7.2并没有成功.这是我的Gem文件和Warbler配置:
#source 'https://rubygems.org'
source "http://bundler-api.herokuapp.com" …Run Code Online (Sandbox Code Playgroud) 对于我正在开发的Rails 3网站,我遇到了一些搜索功能的小问题.我有一个Post看起来像这样的简单模型:
class Post < ActiveRecord::Base
acts_as_taggable
end
Run Code Online (Sandbox Code Playgroud)
我正在使用acts_as_taggable_on我的帖子添加标签更容易一些.当我有一个标记为'rails'的帖子并且我执行以下操作时,一切正常:
@posts = Post.tagged_with("rails")
Run Code Online (Sandbox Code Playgroud)
事情是,我也想搜索帖子的标题.当我有一个标题为'Hello world'并标记为'rails'的帖子时,我希望能够通过搜索'hello' 或 'rails' 找到这篇文章.所以我想要一个LIKE标题列的声明与tagged_with方法acts_as_taggable_on提供的结合.该where范围不工作,因为它使用AND的不是OR.
我希望meta_search能解决这个问题,但这不适合我.我尝试了几件事.以下是我尝试过的两个例子:
@search = Post.search(:tagged_with_or_title_like => params[:search])
@search = Post.search(:title_like => params[:search], :tagged_with => params[:search])
Run Code Online (Sandbox Code Playgroud)
它只是不识别'tagged_with'.这是我第一次使用meta_search,所以我可能在这里做错了.;)我已经阅读了searchlogic与之结合使用的某个地方acts_as_taggable_on,但由于它不支持Rails 3,我无法使用它.
我希望这里有人可以帮我解决这个问题.任何人都知道如何结合acts_as_taggable_on使用meta_search?或者可能知道没有解决方案meta_search?此外,如果有更好的选择acts_as_taggable_on,meta_search我也很乐意听到.:)
编辑:
我没有使用tagged_with或得到它的工作meta_search.它看起来像这样:
Post.select("DISTINCT posts.*").joins(:base_tags).where("posts.title LIKE ? OR tags.name …Run Code Online (Sandbox Code Playgroud) 在我的Widget模型中,我有以下内容:
scope :accessible_to, lambda { |user|
if user.has_role?('admin')
self.all
else
roles = user.roles
role_ids = []
roles.each { |r| role_ids << r.id }
self.joins(:widget_assignments).where('widget_assignments.role_id' => role_ids)
end
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想使用此范围作为Ransack搜索结果的过滤器,因此在我的控制器中我有:
def index
@q = Widget.accessible_to(current_user).search(params[:q])
@widgets = @q.result.order('created_at DESC')
end
Run Code Online (Sandbox Code Playgroud)
这样做会产生以下错误:
未定义的方法`search'for Array:0x007ff9b87a0300
我猜Ransack正在寻找一个ActiveRecord关系对象,而不是一个数组.无论如何,我可以使用我的范围作为Ransack的过滤器吗?
我试图简单地允许在 ActiveAdmin 的“位置”页面上过滤类别。
\n\n我有三个模型:
\n\nclass Location < ActiveRecord::Base\n has_many :categories_locations\n has_many :categories, :through => :categories_locations\n\nclass CategoriesLocation < ActiveRecord::Base\n belongs_to :category\n belongs_to :location\nend\n\nclass Category < ActiveRecord::Base\n has_many :categories_locations\n has_many :locations, :through => :categories_locations\nend\nRun Code Online (Sandbox Code Playgroud)\n\n在我的位置页面上,我使用此过滤器:
\n\nActiveAdmin.register Location do\n filter :name\n filter :category, :collection => proc { Category.all }, :as => :select\nRun Code Online (Sandbox Code Playgroud)\n\n但是,它不断抛出错误。
\n\nundefined method `category_eq' for #<MetaSearch::Searches::Location:0x007fd4f9b965d8>\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试过 filter :categories、filter :categories_locations,但没有任何效果。
\n\n有谁经历过这个 \xe2\x80\x93\xe2\x80\x93 有人有解决方案吗?
\nmeta-search ×10
activeadmin ×3
ruby ×3
activerecord ×2
filter ×1
formtastic ×1
java ×1
jruby ×1
scopes ×1
search ×1
sorting ×1