Query question

How can I do the following

I have a for as follows
<% form_tag companies_path, :method => ‘get’ do %>

Province: <%= hidden_field_tag :test, "test" %> <%= select_tag "province", " Prince Edward Island New Brunswick Nova Scotia Newfoundland" %> Product Category:
<% end %>

I want to dynamically build the SQL statement to look something like
this
SELECT * FROM companies WHERE (0=0 and province = Prince Edward
Island and (pre_fabricated = 1or wood_based_panels = 1))
The values in the where statement can change based on what is selected
in the form.

My Model
if search[:test]
#province = search.delete(:province)
test = search.delete(:test)
action = search.delete(:action)
controller = search.delete(:controller)
sql = “0=0”
search.each do |key, val|
if[:province]
sql += " and #{key} = #{val}"
else
sql += “and (#{key} = #{val} or”
end
sql += “)”
end
find(:all, :conditions => [sql])
else
find(:all)
end
end

This is not working Please help!!

<%=check_box_tag :wood_based_panels, 1, params[:wood_based_panels] %> Wood based panels
<%=check_box_tag :pre_fabricated, 1, params[:pre_fabricated] %> Complete pre-fabricated building and houses
<%=check_box_tag :wood_cabinets, 1, params[:wood_cabinets] %> Wood kitchen cabinets
<%=check_box_tag :wood_windows_doors, 1, params[:wood_windows_doors] %> Wood windows and doors
<%=check_box_tag :wood_flooring, 1, params[:wood_flooring] %> Wood flooring
<%= submit_tag "search", :name => nil %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs