meta-search

How can I use scopes with Ransack in Rails 3?

女生的网名这么多〃 提交于 2019-12-06 02:58:04
问题 In my Widget model I have the following: 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 } Ideally, I would like to use this scope as a filter for Ransack's search results, so in my controller I have: def index @q = Widget.accessible_to(current_user).search(params[:q]) @widgets = @q.result.order('created_at DESC

Rails meta_search gem: sort by count of an associated model

房东的猫 提交于 2019-12-04 03:48:46
I'm using meta_search to sort columns in a table. One of my table columns is a count of the associated records for a particular model. Basically it's this: 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 In my Shop#index view I have a table that lists out the current_inventory_count for each Shop. Is there anyway to use meta_search to order the shops by this count? I can

How to filter IS NULL in ActiveAdmin?

限于喜欢 提交于 2019-12-03 07:03:23
问题 I've a table with an integer column called "map_id", I want to add an activeadmin filter to filter if this column IS NULL or IS NOT NULL. How could this be implemented ? I tried the following filter filter :map_id, :label => 'Assigned', :as => :select, :collection => {:true => nil, :false => ''} But, I get the following error message : undefined method `map_eq' for # 回答1: Not found a good solution but here is a how. filters of Active_admin are accomplished by meta_search, you can override the

How to filter IS NULL in ActiveAdmin?

亡梦爱人 提交于 2019-12-02 21:42:38
I've a table with an integer column called "map_id", I want to add an activeadmin filter to filter if this column IS NULL or IS NOT NULL. How could this be implemented ? I tried the following filter filter :map_id, :label => 'Assigned', :as => :select, :collection => {:true => nil, :false => ''} But, I get the following error message : undefined method `map_eq' for # Not found a good solution but here is a how. filters of Active_admin are accomplished by meta_search, you can override the functions automatically generated by meta_search in your model to get the behavior that you want, the best

Undefined Method stringify! error when using meta_search and active_admin gems

时间秒杀一切 提交于 2019-12-02 15:42:59
问题 I am using the active_admin gem and, since it requires the meta_search gem, I want to provide search functionality outside of the admin pages. I am getting an undefined method error when I provide a string to the Model.search method. According to the meta_search docs, this is all I need to do and all of the active_admin searching works flawlessly. Am I missing something? Gemfile: gem 'activeadmin' gem "meta_search", '>= 1.1.0.pre' Controller: @eventsearch = Event.search(params[:q]) Error

How to set a 0 result in meta_search before user pressing a search button

十年热恋 提交于 2019-12-02 06:09:15
问题 I'm using a meta_search on my rails 3 app. By default (before pressing a search button) meta_search returns all elements of searching model. and I want to set 0 result before user pressing a search button or if search params is blank. I am using meta_search as follows: def index @search = Article.search(params[:search]) if params[:search].blank? @places = nil else @places = @search.all end end What is the best way to set a 0 result if search params is blank ? Thanks 回答1: I don't think that's

How to set a 0 result in meta_search before user pressing a search button

家住魔仙堡 提交于 2019-12-02 00:23:28
I'm using a meta_search on my rails 3 app. By default (before pressing a search button) meta_search returns all elements of searching model. and I want to set 0 result before user pressing a search button or if search params is blank. I am using meta_search as follows: def index @search = Article.search(params[:search]) if params[:search].blank? @places = nil else @places = @search.all end end What is the best way to set a 0 result if search params is blank ? Thanks I don't think that's something that Meta Search really provides out of the box but you can always cheat it. def index @search =

MetaSearch “undefined method `model_name' for NilClass:Class” for global bar search

大城市里の小女人 提交于 2019-11-30 07:42:32
问题 I'm using fantastic MetaSearch by Ernie, but I'm having an annoying issue. In my application.html.erb I have an search field, just like this one on top of StackOverflow page. <%= form_for @search, :url => vagas_path do |f| %> <%= f.text_field :titulo_or_empresa_user_username_contains %> <%= f.submit "", :class => "search-button", :name => "submit" %> <% end %> The problem is that I don't have @search initialized in all actions of all controllers, so when I'm not at Vagas#index I get the

MetaSearch “undefined method `model_name' for NilClass:Class” for global bar search

大憨熊 提交于 2019-11-29 04:56:47
I'm using fantastic MetaSearch by Ernie, but I'm having an annoying issue. In my application.html.erb I have an search field, just like this one on top of StackOverflow page. <%= form_for @search, :url => vagas_path do |f| %> <%= f.text_field :titulo_or_empresa_user_username_contains %> <%= f.submit "", :class => "search-button", :name => "submit" %> <% end %> The problem is that I don't have @search initialized in all actions of all controllers, so when I'm not at Vagas#index I get the "undefined method `model_name' for NilClass:Class" message. What's the best solution for that? =============