Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Model
- def self.filter_products(filter_options)
- scope = System.scoped({})
- scope = scope.scoped :conditions => ["systems.blogging >= 2"] if filter_options.include?("blogging")
- scope = scope.scoped :conditions => ["systems.chat >= 2"] if filter_options.include?("chat")
- scope = scope.scoped :conditions => ["systems.classifieds >= 2"] if filter_options.include?("classifieds")
- scope = scope.scoped :conditions => ["systems.forum >= 2"] if filter_options.include?("forum")
- scope = scope.scoped :conditions => ["systems.events_calendar >= 2"] if filter_options.include?("calendar")
- scope = scope.scoped :conditions => ["systems.link_management >= 2"] if filter_options.include?("links")
- scope = scope.scoped :conditions => ["systems.photo_gallery >= 2"] if filter_options.include?("gallery")
- scope = scope.scoped :conditions => ["systems.search_engine >= 2"] if filter_options.include?("search")
- scope = scope.scoped :conditions => ["systems.syndicated_content >= 2"] if filter_options.include?("rss")
- scope = scope.scoped :conditions => ["systems. >= 2"] if filter_options.include?("")
- scope
- end
- Controller
- def filter
- @filter_url = params[:id]
- @filter_options = @filter_url.split('-') rescue nil
- unless @filter_options.blank?
- @systems = System.filter_products(@filter_options)
- else
- @filter_options = []
- @systems = System.all
- end
- end
- def filter_search
- @options = params[:options]
- @filter = []
- @options.each { |key,value|
- if value == "1"
- @filter << key
- end
- }
- @filters = @filter.sort.join('-')
- unless @filters.empty?
- redirect_to filter_path(@filters)
- else
- flash[:notice] = 'Select a filter condition!'
- redirect_to filter_path
- end
- end
- View
- <% form_for :options, :url => filter_search_path do |f| %>
- <fieldset>
- <ul>
- <li><h4>Functionality</h4>
- <ul>
- <li>
- <%= f.check_box :blogging, filter_status("blogging") %>
- <label for="options_blogging">Blog</label>
- </li>
- <li>
- <%= f.check_box :chat, filter_status("chat") %>
- <label for="options_chat">Chat</label>
- </li>
- <li>
- <%= f.check_box :classifieds, filter_status("classifieds") %>
- <label for="options_classifieds">Classifieds</label>
- </li>
- <li>
- <%= f.check_box :forum, filter_status("forum") %>
- <label for="options_forum">Forum</label>
- </li>
- <li>
- <%= f.check_box :calendar, filter_status("calendar") %>
- <label for="options_calendar">Events calendar</label>
- </li>
- <li>
- <%= f.check_box :links, filter_status("links") %>
- <label for="options_links">Link management</label>
- </li>
- <li>
- <%= f.check_box :gallery, filter_status("gallery") %>
- <label for="options_gallery">Photo gallery</label>
- </li>
- <li>
- <%= f.check_box :search, filter_status("search") %>
- <label for="options_search">Search Engine</label>
- </li>
- <li>
- <%= f.check_box :rss, filter_status("rss") %>
- <label for="options_rss">RSS</label>
- </li>
- </ul>
- </li>
- </ul>
- </fieldset>
- <fieldset class="submit">
- <input type="submit" class="button" id="filter" value="Filter" name="" />
- </fieldset>
- <% end %>
- Config/routes.rb
- map.filter_search '/systems/filter_search', :controller => 'systems', :action => 'filter_search'
- map.filter '/systems/filter/:id', :controller => 'systems', :action => 'filter', :id => nil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement