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
Search Repo:
Michael Hartl (author)
Thu May 08 17:37:19 -0700 2008
commit  b5f56abed08996a3dd7cb7aa5d75f315bbfa5ecc
tree    c38204e173b0304805d53ec8d44e85a9112d0d0f
parent  32a5ad4099beea7b8fd160ccb10443233eef8d77
insoshi / app / helpers / searches_helper.rb
100644 30 lines (26 sloc) 0.875 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
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.
  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'
    "#{dir}/#{part}"
  end
end