public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
insoshi / app / helpers / searches_helper.rb
100644 37 lines (30 sloc) 1.014 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module SearchesHelper
  
  # Return the model to be searched based on params.
  def search_model
    return "Person" if params[:controller] =~ /home/
    return "ForumPost" if params[:controller] =~ /forums/
    params[:model] || params[:controller].classify
  end
  
  def search_type
    if params[:controller] == "forums" or params[:model] == "ForumPost"
      "Forums"
    elsif params[:controller] == "messages" or params[:model] == "Message"
      "Messages"
    else
      "People"
    end
  end
  
  # Return the partial (including path) for the given object.
  # partial can also accept an array of objects (of the same type).
  
  def partial(object)
    object = object.first if object.is_a?(Array)
    klass = object.class.to_s
    dir = klass.tableize # E.g., 'Person' becomes 'people'
    part = dir.singularize # E.g., 'people' becomes 'person'
    admin_search? ? "admin/#{dir}/#{part}" : "#{dir}/#{part}"
  end
 
  private
  
    def admin_search?
      params[:model] =~ /Admin/
    end
end