Example form
<% form_for @search do |f| %>
<ul>
<li>
<%= f.label :item_number_equals, "Item number" %><br />
<%= f.text_field :item_number_equals %>
</li>
<li>
<%= f.label :description_keywords, "Description" %><br />
<%= f.text_field :description_keywords %>
</li>
<li>
<%= f.check_box :in_stock %>
<%= f.label :in_stock, "In Stock?" %>
</li>
<li>
<%= f.label :price_gte, "Price Min" %>
<%= f.text_field :price_gte, :size => 3 %>
<%= f.label :price_lte, "Max" %>
<%= f.text_field :price_lte, :size => 3 %>
</li>
<li>
<%= f.submit "Search" %>
</li>
</ul>
<% end %>
Controller
# app/controllers/products_controller.rb
class ProductsController < ApplicationController
def index
@search = Product.search(params[:search])
@products = @search.all
end
end
What's the best way to sanitize the params in this case? The user could easily modify the HTML or GET request string in attempt to access other data they shouldn't have access to.