Skip to content
This repository
Browse code

Make ApplicationController extend from AC::Base

  • Loading branch information...
commit 67317b6104fffeee2b51b77a1088ca8ef99f6d91 1 parent 9d60525
Pratik authored June 01, 2009
27  railties/guides/source/action_controller_overview.textile
Source Rendered
@@ -191,7 +191,7 @@ Session values are stored using key/value pairs like a hash:
191 191
 <ruby>
192 192
 class ApplicationController < ActionController::Base
193 193
 
194  
-private
  194
+  private
195 195
 
196 196
   # Finds the User with the ID stored in the session with the key
197 197
   # :current_user_id This is a common way to handle user login in
@@ -350,7 +350,8 @@ Before filters may halt the request cycle. A common before filter is one which r
350 350
 class ApplicationController < ActionController::Base
351 351
   before_filter :require_login
352 352
 
353  
-private
  353
+  private
  354
+
354 355
   def require_login
355 356
     unless logged_in?
356 357
       flash[:error] = "You must be logged in to access this section"
@@ -390,10 +391,11 @@ Around filters are responsible for running the action, but they can choose not t
390 391
 <ruby>
391 392
 # Example taken from the Rails API filter documentation:
392 393
 # http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
393  
-class ApplicationController < Application
  394
+class ApplicationController < ActionController::Base
394 395
   around_filter :catch_exceptions
395 396
 
396  
-private
  397
+  private
  398
+
397 399
   def catch_exceptions
398 400
     yield
399 401
   rescue => exception
@@ -575,7 +577,8 @@ class AdminController < ApplicationController
575 577
 
576 578
   before_filter :authenticate
577 579
 
578  
-private
  580
+  private
  581
+
579 582
   def authenticate
580 583
     authenticate_or_request_with_http_basic do |username, password|
581 584
       username == USERNAME &&
@@ -597,7 +600,8 @@ class AdminController < ApplicationController
597 600
 
598 601
   before_filter :authenticate
599 602
 
600  
-private
  603
+  private
  604
+
601 605
   def authenticate
602 606
     authenticate_or_request_with_http_digest do |username|
603 607
       USERS[username]
@@ -626,7 +630,7 @@ class ClientsController < ApplicationController
626 630
               :type => "application/pdf")
627 631
   end
628 632
 
629  
-private
  633
+  private
630 634
 
631 635
   def generate_pdf(client)
632 636
     Prawn::Document.new do
@@ -728,7 +732,8 @@ Here's how you can use +rescue_from+ to intercept all +ActiveRecord::RecordNotFo
728 732
 class ApplicationController < ActionController::Base
729 733
   rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
730 734
 
731  
-private
  735
+  private
  736
+
732 737
   def record_not_found
733 738
     render :text => "404 Not Found", :status => 404
734 739
   end
@@ -741,7 +746,8 @@ Of course, this example is anything but elaborate and doesn't improve on the def
741 746
 class ApplicationController < ActionController::Base
742 747
   rescue_from User::NotAuthorized, :with => :user_not_authorized
743 748
 
744  
-private
  749
+  private
  750
+
745 751
   def user_not_authorized
746 752
     flash[:error] = "You don't have access to this section."
747 753
     redirect_to :back
@@ -757,7 +763,8 @@ class ClientsController < ApplicationController
757 763
     @client = Client.find(params[:id])
758 764
   end
759 765
 
760  
-private
  766
+  private
  767
+
761 768
   # If the user is not authorized, just throw the exception.
762 769
   def check_authorization
763 770
     raise User::NotAuthorized unless current_user.admin?

0 notes on commit 67317b6

Please sign in to comment.
Something went wrong with that request. Please try again.