Filterrific gem for two tables - ruby-on-rails

I am using filterrific gem to add filters in my app. I have parents table and children table. On the children_list page which displays list of all the children with their firstname and their parent's firstname. The issue I am facing is in the search query I want to add the parent.firstname search as well for filterrific. I tried adding a join as below:-
num_or_conds = 2
joins(child: :parent).where(
terms.map { |term|
"(LOWER(children.firstname) LIKE ?) OR (LOWER(parents.firstname) LIKE ?) "
But this didnt do the job. Any idea how this can be achieved.
parent.rb
has_many :children
child.rb
belongs_to :parent
filterrific(
available_filters: [
:search_query,
:with_clinic_date
]
)
scope :search_query, lambda { |query|
return nil if query.blank?
terms = query.downcase.split(/\s+/)
terms = terms.map { |e|
(e.gsub('*', '%') + '%').gsub(/%+/, '%')
}
num_or_conds = 2
where(
terms.map { |term|
"(LOWER(children.firstname) LIKE ?) OR (LOWER(parents.firstname) LIKE ?)"
}.join(' AND '),
*terms.map { |e| [e] * num_or_conds }.flatten
)
}
scope :with_clinic_date, lambda { |ref_date|
where('children.clinic_date = ?', ref_date)
}
end
_children.html.erb
<h1>Children</h1>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Parent First Name</th>
<th>Child firstname</th>
</tr>
</thead>
<tbody>
<% #children.each do |child| %>
<tr>
<td><%=child.parent.firstname %></td>
<td><%=child.firstname %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
children-list.html.erb
<%= form_for_filterrific #filterrific do |f| %>
<div class="row">
<div class="col-sm-3">
Search
<%= f.text_field(
:search_query,
class: 'filterrific-periodically-observed form-control'
) %>
</div>
<div class="col-sm-3">
Request Date
<%= f.date_field(:with_clinic_date, class: 'js-datepicker form-control') %>
</div>
<div class="col-sm-3">
<br>
<%= link_to(
'Reset filters',
reset_filterrific_url,
) %>
</div>
</div>
<%= render_filterrific_spinner %>
<% end %>
<%= render( partial: 'children/children_list') %>
children.js.erb
<% js = escape_javascript(
render(partial: 'children/children_list')
) %>
$("#filterrific_results").html("<%= js %>");

AFAIK, you can't filter two separate classes on the same page. It will use the last defined filterrific instance. When I ran into this problem, I used remote forms with custom action/routes
# routes.rb
resources :parent do
get :filter_parents
resources: children do
get :filter_children
end
end
And then the controllers..
# parents_controller.rb
def index
parents_filter # this would be a helper method running your filter queries
end
def filter_parents
parents_filter # this would be a helper method running your filter queries
end
The children's controller would look similar, just different named helper method/custom action.
And then use a partial for the table. Target the table's container, and use a filter_parents.js.erb and filter_childrens.js.erb file
$('#parents-table').html('<%= escape_javascript render 'path/to/partial'%>')
// same in childrens.js.erb, just target the appropriate table

Related

undefined method `each' for nil:NilClass on an erb array iteration

Im currently working in an Rails 5 application where you can search for a first name or last name and records of the customers of that account would be displayed. However I am getting a Nil object return from search algorithm.
customers_controller:
class CustomersController < ApplicationController
def index
if params[:keywords].present?
#keywords = params[:keywords]
customer_search_term = CustomerSearchTerm.new(#keywords)
#customer = Customer.where(
customer_search_term.where_clause,
customer_search_term.where_args).
order(customer_search_term.order)
else
#customers = []
end
end
end
As you can see if there is no records found is suppose to return an empty array but is returning a Nil object.
customers/index.html.erb
[![<header>
<h1 class="h2">Customer Search</h1>
</header>
<section class="search-form">
<%= form_for :customers, method: :get do |f| %>
<div class="input-group input-group-lg">
<%= label_tag :keywords, nil, class: "sr-only" %>
<%= text_field_tag :keywords, nil,
placeholder: "First Name, Last Name or Email Address",
class: "form-control input-lg" %>
<span class="input-group-btn">
<%= submit_tag "Find Customers", class: "btn btn-primary btn-lg" %>
</span>
</div>
<% end %>
</section>
<section class="search-results">
<header>
<h1 class="h3">Results</h1>
</header>
<table class="table table-striped">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Joined</th>
</tr>
</thead>
<tbody>
<% #customers.each do |customer| %>
<tr>
<td><%= customer.first_name %></td>
<td><%= customer.last_name %></td>
<td><%= customer.email %></td>
<td><%= l customer.created_at.to_date %></td>
</tr>
<% end %>
</tbody>
</table>
</section>][1]][1]
The first thing you should understand is that instance variables return nil if they haven't been set. If you say #fake_var == nil it will be true if you never defined #fake_var before this. You can contrast this with regular local variables, which will raise a NoMethodError if you try and use them before they're defined. For example, puts(fake_var) will raise a NoMethodError for fake_var.
Now look at your template. No matter what it will loop over #customers. If #customers has not been set, you'll see a NoMethodError because you can't call each on nil.
Finally, look at your controller action:
def index
if params[:keywords].present?
#keywords = params[:keywords]
customer_search_term = CustomerSearchTerm.new(#keywords)
#customer = Customer.where(
customer_search_term.where_clause,
customer_search_term.where_args).
order(customer_search_term.order)
else
#customers = []
end
end
Specifically the case when params[:keywords].present?. You never set #customers in this case so it will be nil when the template tries to access it.
I think if you simply replaced #customer = with #customers = it would solve your problem.
you can force it to return array using #to_a which converts nil to empty array
def index
return [] unless params[:keywords]
#keywords = params[:keywords]
customer_search_term = CustomerSearchTerm.new(#keywords)
#customer = Customer.where(
customer_search_term.where_clause,
customer_search_term.where_args).
order(customer_search_term.order
).to_a
end
https://apidock.com/ruby/Array/to_a

Using multiple content_tag in one method in Rails

I am trying to update a Rails 2.3 application to a newer Rails version(4/5).
I have there a method that prints a html table using a list as input, and the caller can customize the display of the rows. I also searched some existing gems that do something similar, but they don't have all the requirements I need. So I have to make this work. The code is
def model_table_2(collection, headers, options = {}, &proc)
options.reverse_merge!({
:id => nil,
:class => nil,
:style => nil,
:placeholder => 'Empty',
:caption => nil,
:summary => nil,
:footer => nil
})
placeholder_unless !collection.empty?, options[:placeholder] do
html_opt = options.slice(:id, :class, :style, :summary)
content_tag(:table, html_opt) do
table_sections = []
table_sections << content_tag(:caption, options[:caption]).to_s if options[:caption]
table_sections << content_tag(:thead,
content_tag(:tr,
headers.collect { |h|
concat(content_tag(:th, h))
}
)
)
if options[:footer]
table_sections << content_tag(:tfoot,
content_tag(:tr, content_tag(:th, concat(options[:footer]), :colspan => headers.size))
)
end
table_sections << content_tag(:tbody,
collection.each_with_index.collect do |row, row_index|
concat(
proc.call(row, cycle('odd', 'even'), row_index)
)
end.join
)
table_sections.join
end
end
end
def placeholder(message = t('general.empty'), options = {}, &proc)
# set default options
o = { :class => 'placeholder', :tag => 'p' }.merge(options)
# wrap the results of the supplied block, or just print out the message
if proc
t = o.delete(:tag)
concat tag(t, o, true), proc.binding
yield
concat "</#{t}>", proc.binding
else
content_tag o.delete(:tag), message, o
end
end
def placeholder_unless(condition, *args, &proc)
condition ? proc.call : concat(placeholder(args), proc.binding)
end
In the view file I call it like this:
<% table_cols = ["No.", "Name"] %>
<% obj_list = [{active: true, name: 'First'}, {active: true, name: 'Second'}, {active: false, name: 'Last'}, nil] %>
<%= model_table_2(obj_list, table_cols, {:class=>'table table-bordered', :caption=>'Model Table Test', :footer=>'The Footer'}) do |record, klass, row_index| -%>
<% if !record.nil? then %>
<% content_tag :tr, :class => klass + (record[:active] ? '' : ' text-muted') do -%>
<td><%= row_index+1 -%></td>
<td><%= record[:name] %></td>
<% end %>
<% else %>
<% content_tag :tr, :class => klass do -%>
<td style="text-align:center;">*</td>
<td>render form</td>
<% end %>
<% end %>
<% end %>
But the output is not how I would expect:
<table class="table table-bordered">
<th>No.</th>
<th>Name</th>
The Footer
<tr class="even">
<td>1</td>
<td>First</td>
</tr>
<tr class="odd">
<td>2</td>
<td>Second</td>
</tr>
<tr class="even text-muted">
<td>3</td>
<td>Last</td>
</tr>
<tr class="odd">
<td>*</td>
<td>render form</td>
</tr>
</table>
As you can see, some of the tags are missing, like caption, thead, tbody, tfoot. I guess it's because the content_tag calls are nested. I tried before without the table_sections array, but it didn't work either.
Also, I have an error when the list is empty, and the code goes to the placeholder... methods.
It's a weird quirk of content_tag but if you nest them you need to use a concat on each return in the inner tags. Otherwise, you just get the last returned string and the inner tags just disappear into the ether. Sadly, in my experience, I've found complex nesting isn't worth the effort of moving into a helper method.
Perhaps, a better approach would be to DRY up the html with a decorator pattern, rails partials, or using something like the cells gem.

ROR application - pass data from view to controller

Trying to pass data from a view to controller using Javascript. How do I do this ? Specifically the information I wish to access in the controller is what option/s have been selected in a variable number (one to many) of selections on the screen.
I have a ROR application I am developing and on the "Companies - Drill Interests" screen I wish to use java/coffeescript to send data and invoke controller action. In the controller I can't get access to all the data I need to respond. That is I can' determine what "Saved Assumption" the user has selected.
From the Companies controller building array (should I be doing this or using another method) of saved assumptions.
def companies_drill_interests
# intial display use first (if present) user drill evaluations
#result_list = Array.new
#company_listings.each do |cl|
#drill_interests.each do |di|
target_share_price = 0
result = Hash.new
result["cl_display_name"] = cl.display_name
result["di"] = di.drill.name
result["target_share_price"] = 0
# if saved assumptions grab first assumption and then first target_share_price
#matched_evaluation_assumption =
EvaluationAssumption.matched_eval_assum(#current_user.id, di.drill_id)
...
# code that builds result ...
end
end
#result_list << result
end
end
end
from the screen partial views/companies/_companies_drill_interests
<%= simple_form_for #company,
html: { class: 'infogroup',
id: "x_company_drill_interests"} do |f| %>
<div class="infogroup-header">Drill Interests</div>
<div class="infogroup-body">
<table border="0" cellpadding="0" cellspacing="0" class="info">
<th class="very_large_column lalign">Drill Name</th>
...
<% if #drill_interests.present? %>
<% index = 0 %>
<% #drill_interests.each do |drill_interest| %>
<%= fields_for "drill_interest[]", drill_interest do |di| %>
<tr>
<td><%= drill_interest.drill.name %></td>
<td class="ralign"><%= drill_interest.equity_percentage %></td>
<% array_name = "evaluation_assumption" + index.to_s %>
<td id="x_user_eval_assum" class='lalign large_column' data-targets="<%= #probability_json %>">
<td> <%= select("mea_user_save_name", "id",
#assumptions[array_name].collect {|r| [ r["mea_user_save_name"], r["id"] ] },
{ :include_blank => false }) %> </td>
<% index += 1 %>
</tr>
<% end %>
...
If the user changes the "Saved Asumptions" selection this is detected in jave/coffeescript. From app/assets/javascript/companies.js.coffee
...
$('#x_company_drill_interests').change((event) ->
company_id = $('.form.companies_drill_interests').attr('data-companyid')
event.preventDefault()
calculateResult company_id
)
calculateResult = (company_id)->
data = $('#x_company_drill_interests').serialize()
$.ajax
url:"/companies/#{company_id}/projection.json",
type:"post"
...
Display statement in Companies Controller for when the action I can't get to work is performed.
class CompaniesController < ApplicationController
...
def projection
puts "================================="
puts "params = " + params.to_s
puts "================================="
...
In the logs output from this statement
params = {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"rFx8TBWnECUCxFiEBQ+0lTmkvhUKEJrUx/SlEQNPEP8=", "mea_user_save_name"=>{"id"=>""}, "action"=>"projection", "controller"=>"companies", "id"=>"18", "format"=>"json"}. The arrays are not present.
Overview of relationships between models.
Company has 0 to many drill_Interests. Each Drill_interest has 0 to many Evaluation_Assumptions (and using Evaluation_Assumptions I wish to display User_Evaluation_Results).
If you wish to see above you can visit the application as per instructions below.
1- go to http://quiet-fortress-3338.herokuapp.com/users/login
2- login with userid = pmlc and password = gmfive99
3- select companies from menu top RHS
4- select ADO
5- Select screen "Companies Drill Interests"
You will see ADO has an interest in both "Temp-01" and "ZZZ-Unlimited" with a number of saved assumptions for both
You are using fields_for, so change:
<td> <%= select("mea_user_save_name", "id",
#assumptions[array_name].collect {|r| [ r["mea_user_save_name"], r["id"] ] },
{ :include_blank => false }) %> </td>
to
<td> <%= di.select("mea_user_save_name", "id",
#assumptions[array_name].collect {|r| [ r["mea_user_save_name"], r["id"] ] },
{ :include_blank => false }) %> </td>
Try to use select_tag instead of select
select_tag statement
select_tag "whatever_name", options_from_collection_for_select(#assumptions[array_name].collect {|r| [ r["mea_user_save_name"], r["id"] ] }, "id", "mea_user_save_name"), include_blank: true
To send and array to backend using fields the fields must be named
<input name="myfieldarray[]">
In this way form.serialize() sends an array for myfieldarray.
check this question
How to pass an array from view to controller in Ruby on Rails
try this.
select_tag "my_array_param[]", options_from_collection_for_select(#assumptions[array_name].collect {|r| [ r["mea_user_save_name"], r["id"] ] }, "id", "mea_user_save_name"), include_blank: true

Rails Average multiple columns

I need to find the average of multiple columns based on a params search across several tables in my VPC controller, but i'm having trouble displaying the average results in the view and also the search is very slow to read from the database. Wondering the best method to do below would be. Would it be best to do the averages in the model? (not sure how this is done though)
Models
class Vpc < ActiveRecord::Base
has_many :results
end
class Result < ActiveRecord::Base
attr_accessible :trial_id, :variety_id, :year, :lint, :turnout, :length_decimal, :length_imperial, :strength, :uniformity, :micronaire, :manual_class
belongs_to :trial, :primary_key => 'trial_id'
belongs_to :variety, :primary_key => 'variety_id'
belongs_to :vpc
has_many :sites, :through => :trial
has_many :growers, :through => :trial
has_many :regions, :through => :sites
end
Controller
class VpcController < ApplicationController
add_breadcrumb "Home", :root_url
add_breadcrumb "Variety Performance Comparison", :vpc_index_path
def index
all = Result.select(:variety_id)
#variety = Variety.where(:variety_id => all).order('variety_name DESC')
#years = Result.select('DISTINCT year')
#regions = Region.all
#irrigations = Trial.select('DISTINCT irrigated').order('irrigated ASC')
end
def search
if params[:variety_one] != params[:variety_two]
#comparison = Result.group('trials.trial_id').having('COUNT(*) = 2').where(variety_id: [params[:variety_one], params[:variety_two]]).
joins(:trial).where('trials.irrigated' => params[:irrigated], 'year' => params[:year]).joins(:regions).where('sites.region_id' => params[:regions])
#vone = #comparison.where('variety_id = ?', params[:variety_one]).select('avg(lint) AS lintone')
#vtwo = #comparison.where('variety_id = ?', params[:variety_two]).select('avg(lint) as linttwo')
#count = #comparison.count('DISTINCT results.trial_id')
#years = #comparison.where('results.year' => params[:year]).select('DISTINCT results.year')
#region = #comparison.where('sites.region_id' => params[:regions]).joins(:regions).group('regions.region_id').select("DISTINCT regions.name")
else
redirect_to vpc_index_url, notice: "Can't compare the same variety"
end
#variety_one = Variety.where('variety_id = ?', params[:variety_one]).group('variety_name')
#variety_two = Variety.where('variety_id = ?', params[:variety_two]).group('variety_name')
add_breadcrumb "Results"
end
end
View Results
<h2>VPC</h2>
<p>We found <%= #count.count %> trials that matched your options, spanning <%= #years.length %> years (<%= #years.map{|y| y.year}.join(", ") %>) and <%= #region.length %> regions (<%= #region.map{|r| r.trial.site.region.name}.join(", ") %>).</p>
<table class="table">
<th></th>
<% #variety_one.each do |v| %>
<th><%= v.variety_name %></th>
<% end %>
<% #variety_two.each do |v| %>
<th><%= v.variety_name %></th>
<% end %>
<th>Difference</th>
<tr>
<td>Yield (bales/ha)</td>
<td><%= "%.2f" % (#vone.lintone/227) unless #vone.blank? %></td>
<td><%= "%.2f" % (#vtwo.lintwo/227) unless #vtwo.blank? %></td>
<td><%= "%.2f" % ((#vone.lintone/227) - (#vtwo.lintwo/227)) unless #lintone.blank? %></td>
</tr>
</tr>
</table>
<hr>
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
<b>Overview of results</b> <span class="pull-right"><i class="icon-chevron-down"></i></span>
</a>
</div>
<div id="collapseOne" class="accordion-body collapse">
<div class="accordion-inner">
<table class="table">
<th>Year</th>
<th>Site</th>
<th>Region</th>
<th>Grower</th>
<% #comparison.each do |v| %>
<tr>
<td><%= link_to v.trial.year, trial_trials_path(trial_id: v.trial_id) %></td>
<td><%= link_to v.trial.site.site_name, trial_trials_path(trial_id: v.trial_id) unless v.trial.site.blank? %></td>
<td><%= link_to v.trial.site.region.name, trial_trials_path(trial_id: v.trial_id) unless v.trial.site.blank? %></td>
<td><%= link_to v.trial.grower.full_name, trial_trials_path(trial_id: v.trial_id) unless v.trial.grower.blank? %></td>
</tr>
<% end %>
</table>
</div>
</div>
</div>
SQL Error
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS lintone) AS count_avg_lint_as_lintone, avg(lint) AS lintone, trials.trial_id ' at line 1: SELECT COUNT(avg(lint) AS lintone) AS count_avg_lint_as_lintone, avg(lint) AS lintone, trials.trial_id AS trials_trial_id FROM `results` INNER JOIN `trials` ON `trials`.`trial_id` = `results`.`trial_id` INNER JOIN `trials` `trials_results_join` ON `trials_results_join`.`trial_id` = `results`.`trial_id` INNER JOIN `sites` ON `sites`.`site_id` = `trials_results_join`.`site_id` INNER JOIN `regions` ON `regions`.`region_id` = `sites`.`region_id` WHERE `results`.`variety_id` IN (2300, 2255) AND `trials`.`irrigated` IN (0, 1, 2) AND `results`.`year` IN (2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013) AND `sites`.`region_id` IN (1, 2, 3, 4, 5, 6, 7, 8) AND (variety_id = '2300') GROUP BY trials.trial_id HAVING COUNT(*) = 2
Looking at your massive controller, I would suggest the following:
#comparison = Result.group('trials.trial_id').having('COUNT(*) = 2').where(variety_id: [params[:variety_one], params[:variety_two]]).
joins(:trial).where('trials.irrigated' => params[:irrigated], 'year' => params[:year]).joins(:regions).where('sites.region_id' => params[:regions])
#count = #comparison.count('DISTINCT results.trial_id')
#years = #comparison.where('results.year' => params[:year]).select('DISTINCT results.year')
#region = #comparison.where('sites.region_id' => params[:regions]).joins(:regions).group('regions.region_id').select("DISTINCT regions.name")
Keep that chunk the same but create a migration to add indexes to increase the performance.
You should not call average so many times but instead do a select on the values you want
#vone = #comparison.where('variety_id = ?', params[:variety_one]).select(avg(lint) as lint, avg...
#vtwo = #comparison.where('variety_id = ?', params[:variety_two]).select(avg(lint) as lint, avg...)
Now in your views you can just get the needed attributes.
After that, have a look at the logs to see if there are any N+1 you can reduce.

Rails multiple select box issue for search

First off here is my model, controller, view:
My model, this is where I have my search code:---------------------------
def self.find_by_lcc(params)
where = []
where << "category = 'Land'"
unless params[:mls].blank?
where << "mls = :mls"
end
unless params[:county].blank?
where << "county = :county"
end
unless params[:acreage_range].blank?
where << "acreage_range = :acreage_range"
end
unless params[:landtype].blank?
where << "landtype = :landtype"
end
unless params[:price_range].blank?
where << "price_range = :price_range"
end
if where.empty?
[]
else
find(:all,
:conditions => [where.join(" AND "), params],
:order => "county, price desc")
end
end
My controller:----------------
def land
#counties = ['Adams', 'Alcorn', 'Amite', 'Attala']
#title = "Browse"
return if params[:commit].nil?
#properties = Property.find_by_lcc(params)
else
'No properties were found'
render :action => 'land_table'
end
My View: ----------------------
<table width="900">
<tr>
<td>
<% form_tag({ :action => "land" }, :method => "get") do %>
<fieldset>
<legend>Search our Land Properties</legend>
<div class="form_row"><p> </p></div>
<div class="form_row">
<label for="mls">MLS Number:</label>
<%= text_field_tag 'mls', params[:mls] %>
</div>
<div class="form_row">
<label for "county"><font color="#ff0000">*County:</font></label>
<%= select_tag "county", options_for_select(#counties), :multiple => true, :size => 6 %>
</div>
<div class="form_row">
<label for "acreage_range">Acreage:</label>
<%= select_tag "acreage_range", options_for_select([['All',''],['1-10','1-10'],['11-25','11-25'],['26-50','26-50'],['51-100','51-100']]) %>
</div>
<div class="form_row">
<label for "landtype">Type:</label>
<%= select_tag "landtype", options_for_select([['All',''],['Waterfront','Waterfront'],['Wooded','Wooded'],['Pasture','Pasture'],['Woods/Pasture','Woods/Pasture'],['Lot','Lot']]) %>
</div>
<div class="form_row">
<label for="price_range"><font color="#ff0000">*Price:</font></label>
<%= select_tag "price_range", options_for_select([['All',''],['0-1,000','0-1,000'],['1,001-10,000','1,001-10,000'],['10,001-50,000','10,001-50,000'],['50,001-100,000','50,001-100,000'],['100,001-150,000']])%>
</div>
<input type="text" style="display: none;" disabled="disabled" size="1" />
<%= submit_tag "Search", :class => "submit" %>
</fieldset>
<% end%>
</td>
</tr>
</table>
The search works fine until I add ", :multiple => true, :size => 6" to make the county field multiple select. Then I get the error:
Processing PublicController#land (for 65.0.81.83 at 2010-04-01 13:11:30) [GET]
Parameters: {"acreage_range"=>"", "commit"=>"Search", "county"=>["Adams", "Amite"], "landtype"=>"", "price_range"=>"", "mls"=>""}
ActiveRecord::StatementInvalid (Mysql::Error: Operand should contain 1 column(s): SELECT * FROM `properties` WHERE (category = 'Land' AND county = 'Adams','Amite') ORDER BY county, price desc):
app/models/property.rb:93:in `find_by_lcc'
app/controllers/public_controller.rb:84:in `land'
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
fcgi (0.8.7) lib/fcgi.rb:117:in `session'
fcgi (0.8.7) lib/fcgi.rb:104:in `each_request'
fcgi (0.8.7) lib/fcgi.rb:36:in `each'
dispatch.fcgi:24
I've tried to make the county, acreage_range, and price_range fields into multiple select boxes numerous ways, but can not get any method to work correctly. Any help would be greatly appreciated.
Thanks,
Try
unless params[:county].blank?
where << "county IN (:county)"
end
OR
unless params[:county].blank?
where << "county IN ( #{params[:county].join(',')})"
end
Try
unless params[:county].blank?
where << "county IN (:county)"
end
EDIT #1
I believe now it'll work even if the "ALL" option is selected
unless params[:county].blank? || params[:county] == "ALL"
where << "county IN (:county)"
end
EDIT #2
I thought the all option was in county. Try this:
unless params[:county].blank?
where << "county IN (:county)"
end
unless params[:acreage_range].blank? || params[:acreage_range] == "ALL"
where << "acreage_range = :acreage_range"
end
Hope it works now :]

Resources