From ac15647bf0e6ed85714dee4e2b14b2e7e6f29320 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 3 Feb 2011 23:51:06 -0500 Subject: [PATCH 1/4] keep options titles consistent to "Options" --- actionpack/lib/action_dispatch/routing/mapper.rb | 10 +++++----- activerecord/lib/active_record/associations.rb | 2 +- .../lib/active_record/relation/finder_methods.rb | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index b28b68ad83..b5ff6e0dcb 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -273,7 +273,7 @@ module ActionDispatch # match 'photos/:id', :to => 'photos#show' # match 'photos/:id', :controller => 'photos', :action => 'show' # - # === Supported options + # === Options # # [:controller] # The route's controller. @@ -549,7 +549,7 @@ module ActionDispatch # The difference here being that the routes generated are like /rails/projects/2, # rather than /accounts/rails/projects/2. # - # === Supported options + # === Options # # Takes same options as Base#match and Resources#resources. # @@ -632,7 +632,7 @@ module ActionDispatch # admin_post PUT /admin/posts/:id(.:format) {:action=>"update", :controller=>"admin/posts"} # admin_post DELETE /admin/posts/:id(.:format) {:action=>"destroy", :controller=>"admin/posts"} # - # === Supported options + # === Options # # The +:path+, +:as+, +:module+, +:shallow_path+ and +:shallow_prefix+ # options all default to the name of the namespace. @@ -950,7 +950,7 @@ module ActionDispatch # PUT /geocoder # DELETE /geocoder # - # === Supported options + # === Options # Takes same options as +resources+. def resource(*resources, &block) options = resources.extract_options! @@ -1013,7 +1013,7 @@ module ActionDispatch # PUT /photos/:id/comments/:id # DELETE /photos/:id/comments/:id # - # === Supported options + # === Options # Takes same options as Base#match as well as: # # [:path_names] diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 891ac52f8a..285ce32e21 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -912,7 +912,7 @@ module ActiveRecord # * Firm#clients.create (similar to c = Client.new("firm_id" => id); c.save; c) # The declaration can also include an options hash to specialize the behavior of the association. # - # === Supported options + # === Options # [:class_name] # Specify the class name of the association. Use it only if that name can't be inferred # from the association name. So has_many :products will by default be linked diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index e447de92a4..7f32e5538e 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -19,7 +19,7 @@ module ActiveRecord # # All approaches accept an options hash as their last parameter. # - # ==== Parameters + # ==== Options # # * :conditions - An SQL fragment like "administrator = 1", ["user_name = ?", username], # or ["user_name = :user_name", { :user_name => user_name }]. See conditions in the intro. From 3a29bfae2cbb956e469942ed1d4ea8c702085a1a Mon Sep 17 00:00:00 2001 From: Brian Morearty Date: Fri, 4 Feb 2011 09:10:07 -0800 Subject: [PATCH 2/4] Change Time.zone= docs. Update the example to show how to reset the current thread's Time.zone upon exiting a request. --- .../lib/active_support/core_ext/time/zones.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index ef401a6d18..ff90d7ca58 100644 --- a/activesupport/lib/active_support/core_ext/time/zones.rb +++ b/activesupport/lib/active_support/core_ext/time/zones.rb @@ -19,14 +19,18 @@ class Time # * A TZInfo::Timezone object. # * An identifier for a TZInfo::Timezone object (e.g., "America/New_York"). # - # Here's an example of how you might set Time.zone on a per request basis -- current_user.time_zone - # just needs to return a string identifying the user's preferred TimeZone: + # Here's an example of how you might set Time.zone on a per request basis and reset it when the request is done. + # current_user.time_zone just needs to return a string identifying the user's preferred time zone: # # class ApplicationController < ActionController::Base - # before_filter :set_time_zone + # around_filter :set_time_zone # # def set_time_zone - # Time.zone = current_user.time_zone + # old_time_zone = Time.zone + # Time.zone = current_user.time_zone if logged_in? + # yield + # ensure + # Time.zone = old_time_zone # end # end def zone=(time_zone) From c56e314866dff5d72c2a90e5e785c9a12d73d22b Mon Sep 17 00:00:00 2001 From: Brian Morearty Date: Sat, 5 Feb 2011 09:07:00 -0800 Subject: [PATCH 3/4] Updates to ActiveRecord::Timestamp documentation. Change ActiveRecord::Base.xyz to config.active_record.xyz in docs. Remove from code samples. Update skip_time_zone_conversion_for_attributes code sample: put the call in the model class. Clarify that skip_time_zone_conversion_for_attributes skips converion when reading. --- activerecord/lib/active_record/timestamp.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index 65d9d1fb19..1511c71ffc 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -9,24 +9,26 @@ module ActiveRecord # # Timestamping can be turned off by setting: # - # ActiveRecord::Base.record_timestamps = false + # config.active_record.record_timestamps = false # # Timestamps are in the local timezone by default but you can use UTC by setting: # - # ActiveRecord::Base.default_timezone = :utc + # config.active_record.default_timezone = :utc # # == Time Zone aware attributes # # By default, ActiveRecord::Base keeps all the datetime columns time zone aware by executing following code. # - # ActiveRecord::Base.time_zone_aware_attributes = true + # config.active_record.time_zone_aware_attributes = true # # This feature can easily be turned off by assigning value false . # - # If your attributes are time zone aware and you desire to skip time zone conversion for certain - # attributes then you can do following: + # If your attributes are time zone aware and you desire to skip time zone conversion to the current Time.zone + # when reading certain attributes then you can do following: # - # Topic.skip_time_zone_conversion_for_attributes = [:written_on] + # class Topic < ActiveRecord::Base + # self.skip_time_zone_conversion_for_attributes = [:written_on] + # end module Timestamp extend ActiveSupport::Concern From 277327bb7f389a140eb4ae7722d64d6cf45e06cf Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Sat, 5 Feb 2011 13:12:09 -0500 Subject: [PATCH 4/4] improve routing docs, mostly for #match --- .../lib/action_dispatch/routing/mapper.rb | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index b5ff6e0dcb..a91b2e88fb 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -247,7 +247,7 @@ module ActionDispatch # # root :to => 'pages#main' # - # For options, see the +match+ method's documentation, as +root+ uses it internally. + # For options, see +match+, as +root+ uses it internally. # # You should put the root route at the top of config/routes.rb, # because this means it will be matched first. As this is the most popular route @@ -256,25 +256,42 @@ module ActionDispatch match '/', options.reverse_merge(:as => :root) end - # Matches a pattern to one or more urls. Any symbols in a pattern are - # interpreted as url parameters: + # Matches a url pattern to one or more routes. Any symbols in a pattern + # are interpreted as url query parameters and thus available as +params+ + # in an action: # - # # sets parameters :controller, :action and :id + # # sets :controller, :action and :id in params # match ':controller/:action/:id' # - # Two of these symbols are special: :controller maps to the - # controller name and :action to the action name within that - # controller. Anything other than :controller or - # :action will be available to the action as part of +params+. - # If a pattern does not have :controller and :action symbols, then they - # must be set in options or shorthand. For example: + # Two of these symbols are special, +:controller+ maps to the controller + # and +:action+ to the controller's action. A pattern can also map + # wildcard segments (globs) to params: + # + # match 'songs/*category/:title' => 'songs#show' + # + # # 'songs/rock/classic/stairway-to-heaven' sets + # # params[:category] = 'rock/classic' + # # params[:title] = 'stairway-to-heaven' + # + # When a pattern points to an internal route, the route's +:action+ and + # +:controller+ should be set in options or hash shorthand. Examples: # # match 'photos/:id' => 'photos#show' # match 'photos/:id', :to => 'photos#show' # match 'photos/:id', :controller => 'photos', :action => 'show' # + # A pattern can also point to a +Rack+ endpoint i.e. anything that + # responds to +call+: + # + # match 'photos/:id' => lambda {|hash| [200, {}, "Coming soon" } + # match 'photos/:id' => PhotoRackApp + # # Yes, controller actions are just rack endpoints + # match 'photos/:id' => PhotosController.action(:show) + # # === Options # + # Any options not seen here are passed on as params with the url. + # # [:controller] # The route's controller. # @@ -302,9 +319,12 @@ module ActionDispatch # match 'path' => 'c#a', :via => [:get, :post] # # [:to] - # Shorthand for specifying :controller and :action. + # Points to a +Rack+ endpoint. Can be an object that responds to + # +call+ or a string representing a controller's action. # - # match 'path' => 'c#a', :to => 'controller#action' + # match 'path', :to => 'controller#action' + # match 'path', :to => lambda { [200, {}, "Success!"] } + # match 'path', :to => RackApp # # [:on] # Shorthand for wrapping routes in a specific RESTful context. Valid @@ -358,6 +378,8 @@ module ActionDispatch # # mount(SomeRackApp => "some_route") # + # For options, see +match+, as +mount+ uses it internally. + # # All mounted applications come with routing helpers to access them. # These are named after the class specified, so for the above example # the helper is either +some_rack_app_path+ or +some_rack_app_url+.