Прежде всего, вот моя модель, контроллер, вид:
Моя модель, здесь у меня есть код поиска: ---------------------------
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
Мой контроллер: ----------------
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'
конец
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>
Поиск работает нормально, пока я не добавлю ",: множественный => истина,: размер => 6", чтобы сделать поле округа множественным выбором. Тогда я получаю ошибку:
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
Я пытался превратить поля county, acreage_range и price_range в несколько полей выбора множеством способов, но не могу заставить любой метод работать правильно. Любая помощь будет принята с благодарностью.
Спасибо