Skip to content

Instantly share code, notes, and snippets.

@Justinwceo
Created November 26, 2011 11:18
Show Gist options
  • Save Justinwceo/1395473 to your computer and use it in GitHub Desktop.
Save Justinwceo/1395473 to your computer and use it in GitHub Desktop.
Radio buttons and Sunspot
searchable do
text :name
boolean :online_search
boolean :offline_search
end
def online_search
store.online_store == true
end
def offline_search
store.online_store == false
end
def search_type=(boolean)
case (boolean)
when 'online'
@online_search = true
@offline_search = false
when 'offline'
@online_search = false
@offline_search = true
when 'all'
@online_search = true
@offline_search = true
else
@online_search = true
@offline_search = true
end
end
class SearchController < ApplicationController
def index
@search = Product.search do |q|
q.fulltext params[:search]
q.with(:search_type, params[:search_type]) if params[:search_type].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 :search_type, "All" %>
<%= radio_button_tag :search_type, "all" %>
<%= label_tag :search_type, "Online" %>
<%= radio_button_tag :search_type, "online" %>
<%= label_tag :search_type, "Offline" %>
<%= radio_button_tag :search_type, "offline" %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment