Created
January 21, 2018 21:46
-
-
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'?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= f.label(:by_source)%>: <%= f.select(:with_source, @filterrific.select_options[:with_source], | |
{ include_hidden: false, include_blank: true }, | |
# { class: 'chosen-select' }, | |
multiple: true | |
) | |
%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LossSource < ApplicationRecord | |
def self.options_for_select | |
order('LOWER(loss_sources.source)').map {|e| [e.source]} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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