cirandas.net

ref: master

plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb


 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
38
39
40
41
42
43
44
45
46
47
48
49
class OpenGraphPlugin::MyprofileController < MyProfileController

  protect 'edit_profile', :profile
  before_filter :set_context

  def enterprise_search
    scope = environment.enterprises.enabled.is_public
    profile_search scope
  end
  def community_search
    scope = environment.communities.is_public
    profile_search scope
  end
  def friend_search
    scope = profile.friends
    profile_search scope
  end

  def track_config
    profile.update! params[:profile_data]
    render partial: 'track_form', locals: {context: context, reload: true}
  end

  protected

  def profile_search scope
    @query = params[:query]
    @profiles = scope.limit(10).order('name ASC').
      where(['name ILIKE ? OR name ILIKE ? OR identifier LIKE ?', "#{@query}%", "% #{@query}%", "#{@query}%"])
    render partial: 'profile_search', locals: {profiles: @profiles}
  end

  def context
    :open_graph
  end

  def set_context
    OpenGraphPlugin.context = self.context
  end

  # inherit routes from core skipping use_relative_controller!
  def url_for options
    options[:controller] = "/#{options[:controller]}" if options.is_a? Hash and options[:controller] and not options[:controller].to_s.starts_with? '/'
    super options
  end
  helper_method :url_for

end