Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/application_controller.rb

Overview

Copyright © 2010, Diaspora Inc. This file is

  licensed under the Affero General Public License version 3 or later.  See
  the COPYRIGHT file.

Direct Known Subclasses

ActivityStreams::PhotosController, AdminsController, ApisController, AppsController, AspectMembershipsController, AspectsController, CommentsController, ContactsController, ConversationVisibilitiesController, ConversationsController, HomeController, LikesController, MessagesController, NotificationsController, PeopleController, PhotosController, PostVisibilitiesController, PostsController, ProfilesController, PublicsController, ServicesController, SocketsController, StatusMessagesController, TagsController, TokensController, UsersController

Instance Method Summary (collapse)

Instance Method Details

- (Object) after_sign_in_path_for(resource)



107
108
109
# File 'app/controllers/application_controller.rb', line 107

def (resource)
    stored_location_for(:user) || aspects_path
end

- (Object) clear_gc_stats



74
75
76
# File 'app/controllers/application_controller.rb', line 74

def clear_gc_stats
  GC.clear_stats if GC.respond_to?(:clear_stats)
end

- (Object) ensure_http_referer_is_set



20
21
22
# File 'app/controllers/application_controller.rb', line 20

def ensure_http_referer_is_set
  request.env['HTTP_REFERER'] ||= '/aspects'
end

- (Object) ensure_page



36
37
38
# File 'app/controllers/application_controller.rb', line 36

def ensure_page
  params[:page] = params[:page] ? params[:page].to_i : 1
end

- (Object) grammatical_gender



103
104
105
# File 'app/controllers/application_controller.rb', line 103

def grammatical_gender
  @grammatical_gender || nil
end

- (Object) redirect_unless_admin



78
79
80
81
82
83
# File 'app/controllers/application_controller.rb', line 78

def redirect_unless_admin
  unless current_user.admin?
    redirect_to root_url, :notice => 'you need to be an admin to do that'
    return
  end
end

- (Object) set_git_header



46
47
48
49
# File 'app/controllers/application_controller.rb', line 46

def set_git_header
  headers['X-Git-Update'] = AppConfig[:git_update]
  headers['X-Git-Revision'] = AppConfig[:git_revision]
end

- (Object) set_grammatical_gender



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/application_controller.rb', line 85

def set_grammatical_gender
  if (user_signed_in? && I18n.inflector.inflected_locale?)
    gender = current_user.profile.gender.to_s.tr('!()[]"\'`*=|/\#.,-:', '').downcase
    unless gender.empty?
      i_langs = I18n.inflector.inflected_locales(:gender)
      i_langs.delete  I18n.locale
      i_langs.unshift I18n.locale
      i_langs.each do |lang|
        token = I18n.inflector.true_token(gender, :gender, lang)
        unless token.nil?
          @grammatical_gender = token
          break
        end
      end
    end
  end
end

- (Object) set_header_data



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/application_controller.rb', line 24

def set_header_data
  if user_signed_in?
    if request.format.html? && !params[:only_posts]
      @aspect = nil
      @notification_count = Notification.for(current_user, :unread =>true).count
      @unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
    end
    @object_aspect_ids = []
    @all_aspects = current_user.aspects
  end
end

- (Object) set_invites



40
41
42
43
44
# File 'app/controllers/application_controller.rb', line 40

def set_invites
  if user_signed_in?
    @invites = current_user.invites
  end
end

- (Object) set_locale



63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/application_controller.rb', line 63

def set_locale
  if user_signed_in?
    I18n.locale = current_user.language
  else
    I18n.locale = request.compatible_language_from AVAILABLE_LANGUAGE_CODES
  end

  WillPaginate::ViewHelpers.pagination_options[:previous_label] = "« #{I18n.t('previous')}"
  WillPaginate::ViewHelpers.pagination_options[:next_label] = "#{I18n.t('next')} »"
end

- (Object) which_action_and_user



51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/application_controller.rb', line 51

def which_action_and_user
  str = "event=request_with_user controller=#{self.class} action=#{self.action_name} "
  if current_user
    str << "uid=#{current_user.id} "
    str << "user_created_at='#{current_user.created_at.to_date.to_s}' user_created_at_unix=#{current_user.created_at.to_i} " if current_user.created_at
    str << "user_non_pending_contact_count=#{current_user.contacts.size} user_contact_count=#{Contact.unscoped.where(:user_id => current_user.id).size} "
  else
    str << 'uid=nil'
  end
  Rails.logger.info str
end