Skip to content

Instantly share code, notes, and snippets.

@crova
Created January 21, 2018 21:46
Show Gist options
  • Save crova/ca6ae18c2c2f6b881853f13a89ce63b2 to your computer and use it in GitHub Desktop.
Save crova/ca6ae18c2c2f6b881853f13a89ce63b2 to your computer and use it in GitHub Desktop.
Any idea on how to create a scope with OR to select more than one 'source'?
<%= f.label(:by_source)%>: <%= f.select(:with_source, @filterrific.select_options[:with_source],
{ include_hidden: false, include_blank: true },
# { class: 'chosen-select' },
multiple: true
)
%>
By the serve log I can see that there is no 'OR' on the search query. How can one add it for my scope under the model?
def index
@filterrific = initialize_filterrific(
Loss,
params[:filterrific],
:persistence_id => false,
select_options: {
with_source: LossSource.options_for_select,
with_category: PartnerCategory.options_for_select
}
) or return
@losses = @filterrific.find.paginate(page: params[:page], per_page: 10).page(params[:page])
respond_to do |format|
format.html
format.js
end
# End of Index
end
class LossSource < ApplicationRecord
def self.options_for_select
order('LOWER(loss_sources.source)').map {|e| [e.source]}
end
end
#scopes
filterrific(
default_filter_params: { sorted_by: 'date_desc' },
available_filters: [
:search_query,
:sorted_by,
:search_for,
:payed_at_gte,
:payed_at_lt,
:with_source,
:with_category
]
)
scope :with_category, lambda { |category| where('losses.category like ?', category)}
ActionView::Template::Error (PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type record
LINE 1: SELECT COUNT(*) FROM "losses" WHERE (losses.source like 'GoD...
^
: SELECT COUNT(*) FROM "losses" WHERE (losses.source like 'GoDaddy','Sendin Blue')):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment