Skip to content

Instantly share code, notes, and snippets.

@Justinwceo
Created November 24, 2011 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Justinwceo/1392014 to your computer and use it in GitHub Desktop.
Save Justinwceo/1392014 to your computer and use it in GitHub Desktop.
Checkboxes
class BusinessStore < ActiveRecord::Base
attr_accessible :website, :name, :address, :phone_number, :online_store
has_many :products
end
class Product < ActiveRecord::Base
attr_accessible :name
belongs_to :business_store
searchable do
text :name
boolean :online_search
boolean :offline_search
end
def online_search
business_store.online_store == true
end
def offline_search
business_store.online_store == false
end
end
class SearchController < ApplicationController
def index
@search = Product.search do
fulltext params[:search]
q.with(:online_search, params[:online_search]) if params[:online_search].present?
q.with(:offline_search, params[:offline_search]) if params[:offline_search].present?
end
@products = @search.results
end
end
<%= form_tag search_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search]" %>
<%= submit_tag "Search", :name => nil %>
<%= label_tag :online_search, 'Online' %>
<%= check_box_tag :online_search, params[:online_search] %>
<%= label_tag :offline_search, 'Offline' %>
<%= check_box_tag :offline_search, params[:offline_search] %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment