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

Filters added to this controller apply to all controllers in the application. Likewise, all the methods added will be available for all controllers.

Methods

Public Instance methods

Gibt den aktuellen Benutzer zurueck

[Source]

    # File app/controllers/application_controller.rb, line 18
18:       def current_user
19:         return @current_user if defined?(@current_user)
20:         @current_user = current_user_session && current_user_session.user
21:       end

Gibt die aktuelle Session zurueck

[Source]

    # File app/controllers/application_controller.rb, line 12
12:       def current_user_session
13:         return @current_user_session if defined?(@current_user_session)
14:         @current_user_session = UserSession.find
15:       end

[Source]

     # File app/controllers/application_controller.rb, line 99
 99:     def get_planet_id
100:       if(cookies[:planet_id] and Planet.find(cookies[:planet_id]).owner == current_user)
101:         return cookies[:planet_id]
102:       else
103:         return current_user.homeplanet.id
104:       end
105:     end

Prueft ob der User eingeloggt ist

[Source]

    # File app/controllers/application_controller.rb, line 24
24:       def logged_in?
25:     
26:         if @current_user
27:           @current_user.logged_in?
28:         else
29:           return false
30:         end
31:       end

Leitet auf die letzte Seite oder den angegebenen default weiter

[Source]

    # File app/controllers/application_controller.rb, line 66
66:     def redirect_back_or_default(default)
67:       redirect_to(session[:return_to] || default)
68:       session[:return_to] = nil
69:     end

Filter-Methode fuer Controller. Verwendung: before_filter :require_no_user Prueft ob der Benutzer NICHT eingeloggt ist, und leitet ihn falls nicht zur Account-Uebersicht weiter.

[Source]

    # File app/controllers/application_controller.rb, line 51
51:     def require_no_user
52:       if current_user
53:         store_location
54:         flash[:notice] = "You must be logged out to access this page"
55:         redirect_to account_url
56:         return false
57:       end
58:     end

Filter-Methode fuer Controller. Verwendung: before_filter :require_user Prueft ob der Benutzer eingeloggt ist, und leitet ihn falls nicht zur login-Seite weiter.

[Source]

    # File app/controllers/application_controller.rb, line 37
37:     def require_user
38:       unless current_user
39:         store_location
40:         flash[:notice] = "You must be logged in to access this page"
41:         redirect_to login_url
42:         return false
43:       end
44:       @planet = Planet.find(get_planet_id)
45:     end

Methode, die PlatenId setzt

[Source]

    # File app/controllers/application_controller.rb, line 88
88:     def set_planet_id
89:       if(params[:planet_id])
90:         cookies[:planet_id] = params[:planet_id]
91:         if(params[:target] and params[:controller])
92:           redirect_to :controller => params[:con], :action => params[:target]
93:         else
94:           redirect_to :controller => "web_overview"
95:         end
96:       end   
97:     end

Speichert in der Session die zuletzt aufgerufene Seite

[Source]

    # File app/controllers/application_controller.rb, line 61
61:     def store_location
62:       session[:return_to] = request.request_uri
63:     end

[Source]

    # File app/controllers/application_controller.rb, line 71
71:     def systems_within_radius(system, radius)
72:       if (system and system.kind_of? SolarSystem and radius >= 0)
73:         x = system.x_coord
74:         y = system.y_coord
75:         z = system.z_coord
76:         systems = SolarSystem.find(:all, :conditions => {
77:           :x_coord => ( (x - radius) .. (x + radius) ),
78:           :y_coord => ( (y - radius) .. (y + radius) ),
79:           :z_coord => ( (z - radius) .. (z + radius) )
80:         })
81:         systems.delete_if { |s| s.calculate_distance( system) >= radius }
82:       else
83:         [Planet.find(get_planet_id).solar_system] #something went terribly wrong
84:       end
85:     end

Scrub sensitive parameters from your log filter_parameter_logging :password

[Source]

     # File app/controllers/application_controller.rb, line 110
110:     def time_format(time)
111:     d = (time / 86400).to_i
112:     h = ((time -= 86400*d) / 3600).to_i
113:     m = ((time -= 3600*h) / 60).to_i
114:     s = (time - 60*m).to_i
115: 
116:     result = ""
117:     if d != 0
118:       result = format("%02dd %02dh %02dm %02ds", d, h, m, s)
119:     else
120:       if h != 0
121:         result = format("%02dh %02dm %02ds", h, m, s)
122:       else
123:         if m != 0
124:           result = format("%02dm %02ds", m, s)
125:         else
126:           result = "%02ds" % s
127:         end
128:       end
129:     end
130:     result
131:   end

[Source]

     # File app/controllers/application_controller.rb, line 137
137:   def valid_building_name?(building_name)
138:     RulesAndRegulations::BUILDINGS.include? building_name
139:   end

[Source]

     # File app/controllers/application_controller.rb, line 141
141:   def valid_research_name?(research_name)
142:     research = ["Waffensysteme","Förderbonus","Antriebsforschung","Konstruktionsgeschwindigkeit"]
143:     research.include? research_name
144:   end

[Source]

     # File app/controllers/application_controller.rb, line 133
133:   def valid_ship_name?(ship_name)
134:     RulesAndRegulations::SPACESHIPS.include? ship_name
135:   end

[Validate]