Class ApplicationController
In: app/controllers/application.rb
Parent: ActionController::Base

his is the application‘s main controller. Features defined here are available in all controllers.

Methods

Included Modules

AuthenticatedSystem PermissionCheck NeedsProfile

Classes and Modules

Module ApplicationController::UsesDesignBlocksHelper

Attributes

environment  [R] 

Public Class methods

[Source]

    # File app/controllers/application.rb, line 13
13:   def self.no_design_blocks
14:     @no_design_blocks = true
15:   end

declares that the given actions cannot be accessed by other HTTP method besides POST.

[Source]

    # File app/controllers/application.rb, line 66
66:   def self.post_only(actions, redirect = { :action => 'index'})
67:     verify :method => :post, :only => actions, :redirect_to => redirect
68:   end

[Source]

    # File app/controllers/application.rb, line 45
45:   def self.refuse_ssl(*options)
46:     before_filter :avoid_ssl, *options
47:   end

[Source]

    # File app/controllers/application.rb, line 33
33:   def self.require_ssl(*options)
34:     before_filter :check_ssl, *options
35:   end

[Source]

    # File app/controllers/application.rb, line 16
16:   def self.uses_design_blocks?
17:     !@no_design_blocks
18:   end

Public Instance methods

[Source]

    # File app/controllers/application.rb, line 48
48:   def avoid_ssl
49:     return true if (!request.ssl? || ENV['RAILS_ENV'] == 'development')
50:     redirect_to(params.merge(:protocol => 'http://'))
51:   end

[Source]

    # File app/controllers/application.rb, line 36
36:   def check_ssl
37:     return true if (request.ssl? || ENV['RAILS_ENV'] == 'development')
38:     redirect_to_ssl
39:   end

[Source]

    # File app/controllers/application.rb, line 40
40:   def redirect_to_ssl
41:     return true if environment.disable_ssl
42:     redirect_to(params.merge(:protocol => 'https://'))
43:   end

[Source]

    # File app/controllers/application.rb, line 19
19:   def uses_design_blocks?
20:     !@no_design_blocks && self.class.uses_design_blocks?
21:   end

Protected Instance methods

[Source]

    # File app/controllers/application.rb, line 8
 8:   def boxes_editor?
 9:     false
10:   end

[Source]

     # File app/controllers/application.rb, line 112
112:   def check_locale
113:     available_locales = Noosfero.available_locales
114: 
115:     # do not accept unsupported locales
116:     if !available_locales.include?(locale.to_s)
117:       old_locale = locale.to_s
118:       # find a similar locale
119:       similar = available_locales.find { |loc| locale.to_s.split('_').first == loc.split('_').first }
120:       if similar
121:         set_locale similar
122:         cookies[:lang] = similar
123:       else
124:         # no similar locale, fallback to default
125:         set_locale(Noosfero.default_locale)
126:         cookies[:lang] = Noosfero.default_locale
127:       end
128:       RAILS_DEFAULT_LOGGER.info('Locale reverted from %s to %s' % [old_locale, locale])
129:     end
130: 
131:     # now set the system locale
132:     system_locale = '%s.utf8' % locale
133:     begin
134:       Locale.setlocale(Locale::LC_TIME, system_locale)
135:     rescue Exception => e
136:       # fallback to C
137:       RAILS_DEFAULT_LOGGER.info("Locale #{system_locale} not available, falling back to the portable \"C\" locale (consider installing the #{system_locale} locale in your system)")
138:       Locale.setlocale(Locale::LC_TIME, 'C')
139:     end
140:   end

TODO: move this logic somewhere else (Domain class?)

[Source]

    # File app/controllers/application.rb, line 79
79:   def detect_stuff_by_domain
80:     @domain = Domain.find_by_name(request.host)
81:     if @domain.nil?
82:       @environment = Environment.default
83:     else
84:       @environment = @domain.environment
85:       @profile = @domain.profile
86:     end
87:   end

[Source]

     # File app/controllers/application.rb, line 142
142:   def load_category
143:     unless params[:category_path].blank?
144:       path = params[:category_path].join('/')
145:       @category = environment.categories.find_by_path(path)
146:       if @category.nil?
147:         render_not_found(path)
148:       end
149:     end
150:   end

[Source]

    # File app/controllers/application.rb, line 89
89:   def load_terminology
90:     Noosfero.terminology = environment.terminology
91:   end

[Source]

     # File app/controllers/application.rb, line 103
103:   def maybe_save_locale
104:     # save locale if forced
105:     if params[:lang]
106:       cookies[:lang] = params[:lang]
107:     end
108:     # force GetText to load a matching locale
109:     GetText.locale = nil
110:   end

[Source]

    # File app/controllers/application.rb, line 93
93:   def render_not_found(path = nil)
94:     @path ||= request.path
95: #    raise "#{@path} not found"
96:     render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404)
97:   end

[Source]

     # File app/controllers/application.rb, line 99
 99:   def user
100:     current_user.person if logged_in?
101:   end

[Validate]