Permalink
Browse files

Merge with docrails

  • Loading branch information...
lifo committed Dec 7, 2008
1 parent 9eca588 commit dbbae5e00e49d3a69dc10978e38299e3f28dd1e1
Showing with 5,289 additions and 1,429 deletions.
  1. +21 −75 actionpack/README
  2. +17 −9 actionpack/lib/action_controller/caching/fragments.rb
  3. +12 −14 actionpack/lib/action_controller/caching/pages.rb
  4. +6 −1 actionpack/lib/action_controller/resources.rb
  5. +4 −2 actionpack/lib/action_controller/routing.rb
  6. +10 −0 actionpack/lib/action_controller/session/active_record_store.rb
  7. +6 −2 actionpack/lib/action_view/base.rb
  8. +1 −1 actionpack/lib/action_view/helpers/tag_helper.rb
  9. +2 −0 actionpack/lib/action_view/template_handlers/erb.rb
  10. +2 −0 activemodel/lib/active_model/errors.rb
  11. +42 −14 activerecord/lib/active_record/base.rb
  12. +2 −0 activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
  13. +9 −6 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  14. +3 −1 activerecord/lib/active_record/migration.rb
  15. +2 −0 activerecord/lib/active_record/schema_dumper.rb
  16. +9 −7 activerecord/lib/active_record/validations.rb
  17. +2 −0 activeresource/lib/active_resource/base.rb
  18. +2 −0 activesupport/lib/active_support/buffered_logger.rb
  19. +2 −0 activesupport/lib/active_support/core_ext/logger.rb
  20. +1 −1 activesupport/lib/active_support/inflector.rb
  21. +2 −1 railties/Rakefile
  22. +26 −0 railties/doc/guides/asciidoc.conf
  23. +9 −4 railties/doc/guides/html/2_2_release_notes.html
  24. +10 −10 railties/doc/guides/html/actioncontroller_basics.html
  25. +451 −3 railties/doc/guides/html/activerecord_validations_callbacks.html
  26. +12 −9 railties/doc/guides/html/association_basics.html
  27. +5 −0 railties/doc/guides/html/authors.html
  28. +104 −20 railties/doc/guides/html/caching_with_rails.html
  29. +125 −2 railties/doc/guides/html/command_line.html
  30. +155 −147 railties/doc/guides/html/configuring.html
  31. +815 −497 railties/doc/guides/html/creating_plugins.html
  32. +65 −27 railties/doc/guides/html/finders.html
  33. +25 −8 railties/doc/guides/html/getting_started_with_rails.html
  34. +1,086 −0 railties/doc/guides/html/i18n.html
  35. +13 −0 railties/doc/guides/html/index.html
  36. +2 −1 railties/doc/guides/html/migrations.html
  37. +4 −4 railties/doc/guides/html/routing_outside_in.html
  38. +5 −4 railties/doc/guides/source/2_2_release_notes.txt
  39. +1 −1 railties/doc/guides/source/actioncontroller_basics/cookies.txt
  40. +2 −2 railties/doc/guides/source/actioncontroller_basics/filters.txt
  41. +2 −2 railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt
  42. +3 −3 railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt
  43. +1 −1 railties/doc/guides/source/actioncontroller_basics/streaming.txt
  44. +1 −1 railties/doc/guides/source/actioncontroller_basics/verification.txt
  45. +284 −4 railties/doc/guides/source/activerecord_validations_callbacks.txt
  46. +15 −9 railties/doc/guides/source/association_basics.txt
  47. +6 −0 railties/doc/guides/source/authors.txt
  48. +99 −20 railties/doc/guides/source/caching_with_rails.txt
  49. +108 −2 railties/doc/guides/source/command_line.txt
  50. +127 −158 railties/doc/guides/source/configuring.txt
  51. +1 −1 railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt
  52. +88 −30 railties/doc/guides/source/creating_plugins/appendix.txt
  53. +6 −2 railties/doc/guides/source/creating_plugins/controllers.txt
  54. +4 −29 railties/doc/guides/source/creating_plugins/core_ext.txt
  55. +50 −0 railties/doc/guides/source/creating_plugins/gems.txt
  56. +144 −0 railties/doc/guides/source/creating_plugins/generator_commands.txt
  57. +98 −0 railties/doc/guides/source/creating_plugins/generators.txt
  58. +1 −3 railties/doc/guides/source/creating_plugins/helpers.txt
  59. +15 −7 railties/doc/guides/source/creating_plugins/index.txt
  60. +0 −156 railties/doc/guides/source/creating_plugins/migration_generator.txt
  61. +213 −0 railties/doc/guides/source/creating_plugins/migrations.txt
  62. +4 −6 railties/doc/guides/source/creating_plugins/models.txt
  63. +0 −69 railties/doc/guides/source/creating_plugins/odds_and_ends.txt
  64. +18 −0 railties/doc/guides/source/creating_plugins/rdoc.txt
  65. +11 −11 railties/doc/guides/source/creating_plugins/{custom_route.txt → routes.txt}
  66. +84 −0 railties/doc/guides/source/creating_plugins/setup.txt
  67. +27 −0 railties/doc/guides/source/creating_plugins/tasks.txt
  68. +165 −0 railties/doc/guides/source/creating_plugins/tests.txt
  69. +51 −25 railties/doc/guides/source/finders.txt
  70. +24 −8 railties/doc/guides/source/getting_started_with_rails.txt
  71. +542 −0 railties/doc/guides/source/i18n.txt
  72. +10 −0 railties/doc/guides/source/index.txt
  73. +1 −1 railties/doc/guides/source/migrations/index.txt
  74. +2 −0 railties/doc/guides/source/migrations/rakeing_around.txt
  75. +4 −4 railties/doc/guides/source/routing_outside_in.txt
  76. +4 −0 railties/doc/guides/source/stylesheets/base.css
  77. +3 −3 railties/doc/guides/source/testing_rails_applications.txt
  78. +1 −1 railties/lib/tasks/databases.rake
View
@@ -10,7 +10,7 @@ Action Pack implements these actions as public methods on Action Controllers
and uses Action Views to implement the template rendering. Action Controllers
are then responsible for handling all the actions relating to a certain part
of an application. This grouping usually consists of actions for lists and for
-CRUDs revolving around a single (or a few) model objects. So ContactController
+CRUDs revolving around a single (or a few) model objects. So ContactsController
would be responsible for listing contacts, creating, deleting, and updating
contacts. A WeblogController could be responsible for both posts and comments.
@@ -33,7 +33,7 @@ A short rundown of the major features:
* Actions grouped in controller as methods instead of separate command objects
and can therefore share helper methods
- BlogController < ActionController::Base
+ CustomersController < ActionController::Base
def show
@customer = find_customer
end
@@ -42,7 +42,7 @@ A short rundown of the major features:
@customer = find_customer
@customer.attributes = params[:customer]
@customer.save ?
- redirect_to(:action => "display") :
+ redirect_to(:action => "show") :
render(:action => "edit")
end
@@ -59,7 +59,7 @@ A short rundown of the major features:
Title: <%= post.title %>
<% end %>
- All post titles: <%= @post.collect{ |p| p.title }.join ", " %>
+ All post titles: <%= @posts.collect{ |p| p.title }.join ", " %>
<% unless @person.is_client? %>
Not for clients to see...
@@ -123,7 +123,7 @@ A short rundown of the major features:
<%= text_field "post", "title", "size" => 30 %>
<%= html_date_select(Date.today) %>
<%= link_to "New post", :controller => "post", :action => "new" %>
- <%= truncate(post.title, 25) %>
+ <%= truncate(post.title, :length => 25) %>
{Learn more}[link:classes/ActionView/Helpers.html]
@@ -177,21 +177,6 @@ A short rundown of the major features:
{Learn more}[link:classes/ActionView/Helpers/JavaScriptHelper.html]
-* Pagination for navigating lists of results
-
- # controller
- def list
- @pages, @people =
- paginate :people, :order => 'last_name, first_name'
- end
-
- # view
- <%= link_to "Previous page", { :page => @pages.current.previous } if @pages.current.previous %>
- <%= link_to "Next page", { :page => @pages.current.next } if @pages.current.next %>
-
- {Learn more}[link:classes/ActionController/Pagination.html]
-
-
* Easy testing of both controller and rendered template through ActionController::TestCase
class LoginControllerTest < ActionController::TestCase
@@ -215,11 +200,11 @@ A short rundown of the major features:
If Active Record is used as the model, you'll have the database debugging
as well:
- Processing WeblogController#create (for 127.0.0.1 at Sat Jun 19 14:04:23)
- Params: {"controller"=>"weblog", "action"=>"create",
+ Processing PostsController#create (for 127.0.0.1 at Sat Jun 19 14:04:23)
+ Params: {"controller"=>"posts", "action"=>"create",
"post"=>{"title"=>"this is good"} }
SQL (0.000627) INSERT INTO posts (title) VALUES('this is good')
- Redirected to http://test/weblog/display/5
+ Redirected to http://example.com/posts/5
Completed in 0.221764 (4 reqs/sec) | DB: 0.059920 (27%)
You specify a logger through a class method, such as:
@@ -256,30 +241,6 @@ A short rundown of the major features:
{Learn more}[link:classes/ActionController/Caching.html]
-* Component requests from one controller to another
-
- class WeblogController < ActionController::Base
- # Performs a method and then lets hello_world output its render
- def delegate_action
- do_other_stuff_before_hello_world
- render_component :controller => "greeter", :action => "hello_world"
- end
- end
-
- class GreeterController < ActionController::Base
- def hello_world
- render_text "Hello World!"
- end
- end
-
- The same can be done in a view to do a partial rendering:
-
- Let's see a greeting:
- <%= render_component :controller => "greeter", :action => "hello_world" %>
-
- {Learn more}[link:classes/ActionController/Components.html]
-
-
* Powerful debugging mechanism for local requests
All exceptions raised on actions performed on the request of a local user
@@ -336,7 +297,7 @@ A short rundown of the major features:
class WeblogController < ActionController::Base
def create
post = Post.create(params[:post])
- redirect_to :action => "display", :id => post.id
+ redirect_to :action => "show", :id => post.id
end
end
@@ -362,7 +323,7 @@ methods:
@posts = Post.find(:all)
end
- def display
+ def show
@post = Post.find(params[:id])
end
@@ -372,7 +333,7 @@ methods:
def create
@post = Post.create(params[:post])
- redirect_to :action => "display", :id => @post.id
+ redirect_to :action => "show", :id => @post.id
end
end
@@ -385,47 +346,32 @@ request from the web-server (like to be Apache).
And the templates look like this:
- weblog/layout.erb:
+ weblog/layout.html.erb:
<html><body>
<%= yield %>
</body></html>
- weblog/index.erb:
+ weblog/index.html.erb:
<% for post in @posts %>
- <p><%= link_to(post.title, :action => "display", :id => post.id %></p>
+ <p><%= link_to(post.title, :action => "show", :id => post.id) %></p>
<% end %>
- weblog/display.erb:
+ weblog/show.html.erb:
<p>
- <b><%= post.title %></b><br/>
- <b><%= post.content %></b>
+ <b><%= @post.title %></b><br/>
+ <b><%= @post.content %></b>
</p>
- weblog/new.erb:
+ weblog/new.html.erb:
<%= form "post" %>
This simple setup will list all the posts in the system on the index page,
which is called by accessing /weblog/. It uses the form builder for the Active
Record model to make the new screen, which in turn hands everything over to
the create action (that's the default target for the form builder when given a
-new model). After creating the post, it'll redirect to the display page using
-an URL such as /weblog/display/5 (where 5 is the id of the post).
-
-
-== Examples
-
-Action Pack ships with three examples that all demonstrate an increasingly
-detailed view of the possibilities. First is blog_controller that is just a
-single file for the whole MVC (but still split into separate parts). Second is
-the debate_controller that uses separate template files and multiple screens.
-Third is the address_book_controller that uses the layout feature to separate
-template casing from content.
-
-Please note that you might need to change the "shebang" line to
-#!/usr/local/env ruby, if your Ruby is not placed in /usr/local/bin/ruby
+new model). After creating the post, it'll redirect to the show page using
+an URL such as /weblog/5 (where 5 is the id of the post).
-Also note that these examples are all for demonstrating using Action Pack on
-its own. Not for when it's used inside of Rails.
== Download
@@ -460,4 +406,4 @@ And as Jim from Rake says:
Feel free to submit commits or feature requests. If you send a patch,
remember to update the corresponding unit tests. If fact, I prefer
- new feature to be submitted in the form of new unit tests.
+ new feature to be submitted in the form of new unit tests.
@@ -83,15 +83,23 @@ def fragment_exist?(key, options = nil)
end
end
- # Name can take one of three forms:
- # * String: This would normally take the form of a path like "pages/45/notes"
- # * Hash: Is treated as an implicit call to url_for, like { :controller => "pages", :action => "notes", :id => 45 }
- # * Regexp: Will destroy all the matched fragments, example:
- # %r{pages/\d*/notes}
- # Ensure you do not specify start and finish in the regex (^$) because
- # the actual filename matched looks like ./cache/filename/path.cache
- # Regexp expiration is only supported on caches that can iterate over
- # all keys (unlike memcached).
+ # Removes fragments from the cache.
+ #
+ # +key+ can take one of three forms:
+ # * String - This would normally take the form of a path, like
+ # <tt>"pages/45/notes"</tt>.
+ # * Hash - Treated as an implicit call to +url_for+, like
+ # <tt>{:controller => "pages", :action => "notes", :id => 45}</tt>
+ # * Regexp - Will remove any fragment that matches, so
+ # <tt>%r{pages/\d*/notes}</tt> might remove all notes. Make sure you
+ # don't use anchors in the regex (<tt>^</tt> or <tt>$</tt>) because
+ # the actual filename matched looks like
+ # <tt>./cache/filename/path.cache</tt>. Note: Regexp expiration is
+ # only supported on caches that can iterate over all keys (unlike
+ # memcached).
+ #
+ # +options+ is passed through to the cache store's <tt>delete</tt>
+ # method (or <tt>delete_matched</tt>, for Regexp keys.)
def expire_fragment(key, options = nil)
return unless cache_configured?
@@ -33,28 +33,26 @@ module Caching
#
# Additionally, you can expire caches using Sweepers that act on changes in the model to determine when a cache is supposed to be
# expired.
- #
- # == Setting the cache directory
- #
- # The cache directory should be the document root for the web server and is set using <tt>Base.page_cache_directory = "/document/root"</tt>.
- # For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>RAILS_ROOT + "/public"</tt>). Changing
- # this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your
- # web server to look in the new location for cached files.
- #
- # == Setting the cache extension
- #
- # Most Rails requests do not have an extension, such as <tt>/weblog/new</tt>. In these cases, the page caching mechanism will add one in
- # order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is <tt>.html</tt>.
- # If you want something else, like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension. In cases where a request already has an
- # extension, such as <tt>.xml</tt> or <tt>.rss</tt>, page caching will not add an extension. This allows it to work well with RESTful apps.
module Pages
def self.included(base) #:nodoc:
base.extend(ClassMethods)
base.class_eval do
@@page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
+ ##
+ # :singleton-method:
+ # The cache directory should be the document root for the web server and is set using <tt>Base.page_cache_directory = "/document/root"</tt>.
+ # For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>RAILS_ROOT + "/public"</tt>). Changing
+ # this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your
+ # web server to look in the new location for cached files.
cattr_accessor :page_cache_directory
@@page_cache_extension = '.html'
+ ##
+ # :singleton-method:
+ # Most Rails requests do not have an extension, such as <tt>/weblog/new</tt>. In these cases, the page caching mechanism will add one in
+ # order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is <tt>.html</tt>.
+ # If you want something else, like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension. In cases where a request already has an
+ # extension, such as <tt>.xml</tt> or <tt>.rss</tt>, page caching will not add an extension. This allows it to work well with RESTful apps.
cattr_accessor :page_cache_extension
end
end
@@ -283,7 +283,12 @@ def initialize(entity, options)
# * <tt>:new</tt> - Same as <tt>:collection</tt>, but for actions that operate on the new \resource action.
# * <tt>:controller</tt> - Specify the controller name for the routes.
# * <tt>:singular</tt> - Specify the singular name used in the member routes.
- # * <tt>:requirements</tt> - Set custom routing parameter requirements.
+ # * <tt>:requirements</tt> - Set custom routing parameter requirements; this is a hash of either
+ # regular expressions (which must match for the route to match) or extra parameters. For example:
+ #
+ # map.resource :profile, :path_prefix => ':name', :requirements => { :name => /[a-zA-Z]+/, :extra => 'value' }
+ #
+ # will only match if the first part is alphabetic, and will pass the parameter :extra to the controller.
# * <tt>:conditions</tt> - Specify custom routing recognition conditions. \Resources sets the <tt>:method</tt> value for the method-specific routes.
# * <tt>:as</tt> - Specify a different \resource name to use in the URL path. For example:
# # products_path == '/productos'
@@ -83,9 +83,11 @@ module ActionController
# This sets up +blog+ as the default controller if no other is specified.
# This means visiting '/' would invoke the blog controller.
#
- # More formally, you can define defaults in a route with the <tt>:defaults</tt> key.
+ # More formally, you can include arbitrary parameters in the route, thus:
#
- # map.connect ':controller/:action/:id', :action => 'show', :defaults => { :page => 'Dashboard' }
+ # map.connect ':controller/:action/:id', :action => 'show', :page => 'Dashboard'
+ #
+ # This will pass the :page parameter to all incoming requests that match this route.
#
# Note: The default routes, as provided by the Rails generator, make all actions in every
# controller accessible via GET requests. You should consider removing them or commenting
@@ -56,6 +56,8 @@ def model
class ActiveRecordStore
# The default Active Record class.
class Session < ActiveRecord::Base
+ ##
+ # :singleton-method:
# Customizable data column name. Defaults to 'data'.
cattr_accessor :data_column_name
self.data_column_name = 'data'
@@ -166,17 +168,25 @@ def raise_on_session_data_overflow!
# binary session data in a +text+ column. For higher performance,
# store in a +blob+ column instead and forgo the Base64 encoding.
class SqlBypass
+ ##
+ # :singleton-method:
# Use the ActiveRecord::Base.connection by default.
cattr_accessor :connection
+ ##
+ # :singleton-method:
# The table name defaults to 'sessions'.
cattr_accessor :table_name
@@table_name = 'sessions'
+ ##
+ # :singleton-method:
# The session id field defaults to 'session_id'.
cattr_accessor :session_id_column
@@session_id_column = 'session_id'
+ ##
+ # :singleton-method:
# The data field defaults to 'data'.
cattr_accessor :data_column
@@data_column = 'data'
@@ -183,13 +183,17 @@ def self.exempt_from_layout(*extensions)
@@exempt_from_layout.merge(regexps)
end
+ @@debug_rjs = false
+ ##
+ # :singleton-method:
# Specify whether RJS responses should be wrapped in a try/catch block
# that alert()s the caught exception (and then re-raises it).
- @@debug_rjs = false
cattr_accessor :debug_rjs
- # A warning will be displayed whenever an action results in a cache miss on your view paths.
@@warn_cache_misses = false
+ ##
+ # :singleton-method:
+ # A warning will be displayed whenever an action results in a cache miss on your view paths.
cattr_accessor :warn_cache_misses
attr_internal :request
@@ -97,7 +97,7 @@ def cdata_section(content)
# Returns an escaped version of +html+ without affecting existing escaped entities.
#
# ==== Examples
- # escape_once("1 > 2 &amp; 3")
+ # escape_once("1 < 2 &amp; 3")
# # => "1 &lt; 2 &amp; 3"
#
# escape_once("&lt;&lt; Accept & Checkout")
@@ -3,6 +3,8 @@ module TemplateHandlers
class ERB < TemplateHandler
include Compilable
+ ##
+ # :singleton-method:
# Specify trim mode for the ERB compiler. Defaults to '-'.
# See ERb documentation for suitable values.
cattr_accessor :erb_trim_mode
@@ -24,6 +24,8 @@ class Errors < Hash
:even => "must be even"
}
+ ##
+ # :singleton-method:
# Holds a hash with all the default error messages that can be replaced by your own copy or localizations.
cattr_accessor :default_error_messages
Oops, something went wrong.

0 comments on commit dbbae5e

Please sign in to comment.