Created
November 24, 2011 19:02
-
-
Save Justinwceo/1392014 to your computer and use it in GitHub Desktop.
Checkboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BusinessStore < ActiveRecord::Base | |
attr_accessible :website, :name, :address, :phone_number, :online_store | |
has_many :products | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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