Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lifo/docrails
Browse files Browse the repository at this point in the history
Conflicts:
	guides/source/ruby_on_rails_guides_guidelines.textile
  • Loading branch information
vijaydev committed Mar 24, 2012
2 parents 780ab58 + 2fab826 commit 014498e
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 99 deletions.
8 changes: 4 additions & 4 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module ActionMailer #:nodoc:
# #
# $ rails generate mailer Notifier # $ rails generate mailer Notifier
# #
# The generated model inherits from <tt>ActionMailer::Base</tt>. Emails are defined by creating methods # The generated model inherits from <tt>ActionMailer::Base</tt>. A mailer model defines methods
# within the model which are then used to set variables to be used in the mail template, to # used to generate an email message. In these methods, you can setup variables to be used in
# change options on the mail, or to add attachments. # the mailer views, options on the mail itself such as the <tt>:from</tt> address, and attachments.
# #
# Examples: # Examples:
# #
# class Notifier < ActionMailer::Base # class Notifier < ActionMailer::Base
# default :from => 'no-reply@example.com', # default :from => 'no-reply@example.com',
# :return_path => 'system@example.com' # :return_path => 'system@example.com'
# #
# def welcome(recipient) # def welcome(recipient)
# @account = recipient # @account = recipient
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/renderer/partial_renderer.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module ActionView
# #
# <%= render :partial => "account", :object => @buyer %> # <%= render :partial => "account", :object => @buyer %>
# #
# would provide the +@buyer+ object to the partial, available under the local variable +account+ and is # would provide the <tt>@buyer</tt> object to the partial, available under the local variable +account+ and is
# equivalent to: # equivalent to:
# #
# <%= render :partial => "account", :locals => { :account => @buyer } %> # <%= render :partial => "account", :locals => { :account => @buyer } %>
Expand Down
14 changes: 14 additions & 0 deletions activerecord/lib/active_record/inheritance.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ def base_class
end end


# Set this to true if this is an abstract class (see <tt>abstract_class?</tt>). # Set this to true if this is an abstract class (see <tt>abstract_class?</tt>).
# If you are using inheritance with ActiveRecord and don't want child classes
# to utilize the implied STI table name of the parent class, this will need to be true.
# For example, given the following:
#
# class SuperClass < ActiveRecord::Base
# self.abstract_class = true
# end
# class Child < SuperClass
# self.table_name = 'the_table_i_really_want'
# end
#
#
# <tt>self.abstract_class = true</tt> is required to make <tt>Child<.find,.create, or any Arel method></tt> use <tt>the_table_i_really_want</tt> instead of a table called <tt>super_classes</tt>
#
attr_accessor :abstract_class attr_accessor :abstract_class


# Returns whether this class is an abstract class or not. # Returns whether this class is an abstract class or not.
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def scoping
# # Update all books with 'Rails' in their title # # Update all books with 'Rails' in their title
# Book.update_all "author = 'David'", "title LIKE '%Rails%'" # Book.update_all "author = 'David'", "title LIKE '%Rails%'"
# #
# # Update all avatars migrated more than a week ago # # Update all avatars migrated more recently than a week ago
# Avatar.update_all ['migrated_at = ?', Time.now.utc], ['migrated_at > ?', 1.week.ago] # Avatar.update_all ['migrated_at = ?', Time.now.utc], ['migrated_at > ?', 1.week.ago]
# #
# # Update all books that match conditions, but limit it to 5 ordered by date # # Update all books that match conditions, but limit it to 5 ordered by date
Expand Down
31 changes: 15 additions & 16 deletions guides/source/api_documentation_guidelines.textile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ endprologue.


h3. RDoc h3. RDoc


The Rails API documentation is generated with RDoc 2.5. Please consult the documentation for help with the "markup":http://rdoc.rubyforge.org/RDoc/Markup.html, and take into account also these "additional directives":http://rdoc.rubyforge.org/RDoc/Parser/Ruby.html. The Rails API documentation is generated with RDoc. Please consult the documentation for help with the "markup":http://rdoc.rubyforge.org/RDoc/Markup.html, and also take into account these "additional directives":http://rdoc.rubyforge.org/RDoc/Parser/Ruby.html.


h3. Wording h3. Wording


Write simple, declarative sentences. Brevity is a plus: get to the point. Write simple, declarative sentences. Brevity is a plus: get to the point.


Write in present tense: "Returns a hash that...", rather than "Returned a hash that..." or "Will return a hash that...". Write in present tense: "Returns a hash that...", rather than "Returned a hash that..." or "Will return a hash that...".


Start comments in upper case, follow regular punctuation rules: Start comments in upper case. Follow regular punctuation rules:


<ruby> <ruby>
# Declares an attribute reader backed by an internally-named instance variable. # Declares an attribute reader backed by an internally-named instance variable.
Expand All @@ -23,7 +23,7 @@ def attr_internal_reader(*attrs)
end end
</ruby> </ruby>


Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the recommended idioms in edge, reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage. Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.


Documentation has to be concise but comprehensive. Explore and document edge cases. What happens if a module is anonymous? What if a collection is empty? What if an argument is nil? Documentation has to be concise but comprehensive. Explore and document edge cases. What happens if a module is anonymous? What if a collection is empty? What if an argument is nil?


Expand All @@ -41,10 +41,9 @@ h3. Example Code


Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas. Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas.


Use two spaces to indent chunks of code--that is two spaces with respect to the left margin; the examples Use two spaces to indent chunks of code--that is, for markup purposes, two spaces with respect to the left margin. The examples themselves should use "Rails coding conventions":contributing_to_ruby_on_rails.html#follow-the-coding-conventions.
themselves should use "Rails coding conventions":contributing_to_ruby_on_rails.html#follow-the-coding-conventions.


Short docs do not need an explicit "Examples" label to introduce snippets, they just follow paragraphs: Short docs do not need an explicit "Examples" label to introduce snippets; they just follow paragraphs:


<ruby> <ruby>
# Converts a collection of elements into a formatted string by calling # Converts a collection of elements into a formatted string by calling
Expand All @@ -64,7 +63,7 @@ On the other hand, big chunks of structured documentation may have a separate "E
# Person.exists?(['name LIKE ?', "%#{query}%"]) # Person.exists?(['name LIKE ?', "%#{query}%"])
</ruby> </ruby>


The result of expressions follow them and are introduced by "# => ", vertically aligned: The results of expressions follow them and are introduced by "# => ", vertically aligned:


<ruby> <ruby>
# For checking if a fixnum is even or odd. # For checking if a fixnum is even or odd.
Expand Down Expand Up @@ -98,7 +97,7 @@ On the other hand, regular comments do not use an arrow:


h3. Filenames h3. Filenames


As a rule of thumb use filenames relative to the application root: As a rule of thumb, use filenames relative to the application root:


<plain> <plain>
config/routes.rb # YES config/routes.rb # YES
Expand All @@ -111,12 +110,12 @@ h3. Fonts
h4. Fixed-width Font h4. Fixed-width Font


Use fixed-width fonts for: Use fixed-width fonts for:
* constants, in particular class and module names * Constants, in particular class and module names.
* method names * Method names.
* literals like +nil+, +false+, +true+, +self+ * Literals like +nil+, +false+, +true+, +self+.
* symbols * Symbols.
* method parameters * Method parameters.
* file names * File names.


<ruby> <ruby>
class Array class Array
Expand Down Expand Up @@ -146,7 +145,7 @@ The description starts in upper case and ends with a full stop—it's standard E


h3. Dynamically Generated Methods h3. Dynamically Generated Methods


Methods created with +(module|class)_eval(STRING)+ have a comment by their side with an instance of the generated code. That comment is 2 spaces apart from the template: Methods created with +(module|class)_eval(STRING)+ have a comment by their side with an instance of the generated code. That comment is 2 spaces away from the template:


<ruby> <ruby>
for severity in Severity.constants for severity in Severity.constants
Expand All @@ -162,7 +161,7 @@ for severity in Severity.constants
end end
</ruby> </ruby>


If the resulting lines are too wide, say 200 columns or more, we put the comment above the call: If the resulting lines are too wide, say 200 columns or more, put the comment above the call:


<ruby> <ruby>
# def self.find_by_login_and_activated(*args) # def self.find_by_login_and_activated(*args)
Expand Down
4 changes: 3 additions & 1 deletion guides/source/asset_pipeline.textile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ cannot see application objects or methods. *Heroku requires this to be false.*
WARNING: If you set +config.assets.initialize_on_precompile+ to false, be sure to WARNING: If you set +config.assets.initialize_on_precompile+ to false, be sure to
test +rake assets:precompile+ locally before deploying. It may expose bugs where test +rake assets:precompile+ locally before deploying. It may expose bugs where
your assets reference application objects or methods, since those are still your assets reference application objects or methods, since those are still
in scope in development mode regardless of the value of this flag. in scope in development mode regardless of the value of this flag. Changing this flag also effects
engines. Engines can define assets for precompilation as well. Since the complete environment is not loaded,
engines (or other gems) will not be loaded which can cause missing assets.


Capistrano (v2.8.0 and above) includes a recipe to handle this in deployment. Add the following line to +Capfile+: Capistrano (v2.8.0 and above) includes a recipe to handle this in deployment. Add the following line to +Capfile+:


Expand Down
4 changes: 2 additions & 2 deletions guides/source/association_basics.textile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ In designing a data model, you will sometimes find a model that should have a re


<ruby> <ruby>
class Employee < ActiveRecord::Base class Employee < ActiveRecord::Base
has_many :subordinates, :class_name => "Employee" has_many :subordinates, :class_name => "Employee",
belongs_to :manager, :class_name => "Employee",
:foreign_key => "manager_id" :foreign_key => "manager_id"
belongs_to :manager, :class_name => "Employee"
end end
</ruby> </ruby>


Expand Down
18 changes: 10 additions & 8 deletions guides/source/caching_with_rails.textile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ However, it's important to note that query caches are created at the start of an


h3. Cache Stores h3. Cache Stores


Rails provides different stores for the cached data created by action and fragment caches. Page caches are always stored on disk. Rails provides different stores for the cached data created by <b>action</b> and <b>fragment</b> caches.

TIP: Page caches are always stored on disk.


h4. Configuration h4. Configuration


Expand All @@ -267,7 +269,7 @@ You can set up your application's default cache store by calling +config.cache_s
config.cache_store = :memory_store config.cache_store = :memory_store
</ruby> </ruby>


Alternatively, you can call +ActionController::Base.cache_store+ outside of a configuration block. NOTE: Alternatively, you can call +ActionController::Base.cache_store+ outside of a configuration block.


You can access the cache by calling +Rails.cache+. You can access the cache by calling +Rails.cache+.


Expand All @@ -294,7 +296,7 @@ h4. ActiveSupport::Cache::MemoryStore
This cache store keeps entries in memory in the same Ruby process. The cache store has a bounded size specified by the +:size+ options to the initializer (default is 32Mb). When the cache exceeds the allotted size, a cleanup will occur and the least recently used entries will be removed. This cache store keeps entries in memory in the same Ruby process. The cache store has a bounded size specified by the +:size+ options to the initializer (default is 32Mb). When the cache exceeds the allotted size, a cleanup will occur and the least recently used entries will be removed.


<ruby> <ruby>
ActionController::Base.cache_store = :memory_store, :size => 64.megabytes config.cache_store = :memory_store, :size => 64.megabytes
</ruby> </ruby>


If you're running multiple Ruby on Rails server processes (which is the case if you're using mongrel_cluster or Phusion Passenger), then your Rails server process instances won't be able to share cache data with each other. This cache store is not appropriate for large application deployments, but can work well for small, low traffic sites with only a couple of server processes or for development and test environments. If you're running multiple Ruby on Rails server processes (which is the case if you're using mongrel_cluster or Phusion Passenger), then your Rails server process instances won't be able to share cache data with each other. This cache store is not appropriate for large application deployments, but can work well for small, low traffic sites with only a couple of server processes or for development and test environments.
Expand All @@ -306,7 +308,7 @@ h4. ActiveSupport::Cache::FileStore
This cache store uses the file system to store entries. The path to the directory where the store files will be stored must be specified when initializing the cache. This cache store uses the file system to store entries. The path to the directory where the store files will be stored must be specified when initializing the cache.


<ruby> <ruby>
ActionController::Base.cache_store = :file_store, "/path/to/cache/directory" config.cache_store = :file_store, "/path/to/cache/directory"
</ruby> </ruby>


With this cache store, multiple server processes on the same host can share a cache. Servers processes running on different hosts could share a cache by using a shared file system, but that set up would not be ideal and is not recommended. The cache store is appropriate for low to medium traffic sites that are served off one or two hosts. With this cache store, multiple server processes on the same host can share a cache. Servers processes running on different hosts could share a cache by using a shared file system, but that set up would not be ideal and is not recommended. The cache store is appropriate for low to medium traffic sites that are served off one or two hosts.
Expand All @@ -322,15 +324,15 @@ When initializing the cache, you need to specify the addresses for all memcached
The +write+ and +fetch+ methods on this cache accept two additional options that take advantage of features specific to memcached. You can specify +:raw+ to send a value directly to the server with no serialization. The value must be a string or number. You can use memcached direct operation like +increment+ and +decrement+ only on raw values. You can also specify +:unless_exist+ if you don't want memcached to overwrite an existing entry. The +write+ and +fetch+ methods on this cache accept two additional options that take advantage of features specific to memcached. You can specify +:raw+ to send a value directly to the server with no serialization. The value must be a string or number. You can use memcached direct operation like +increment+ and +decrement+ only on raw values. You can also specify +:unless_exist+ if you don't want memcached to overwrite an existing entry.


<ruby> <ruby>
ActionController::Base.cache_store = :mem_cache_store, "cache-1.example.com", "cache-2.example.com" config.cache_store = :mem_cache_store, "cache-1.example.com", "cache-2.example.com"
</ruby> </ruby>


h4. ActiveSupport::Cache::EhcacheStore h4. ActiveSupport::Cache::EhcacheStore


If you are using JRuby you can use Terracotta's Ehcache as the cache store for your application. Ehcache is an open source Java cache that also offers an enterprise version with increased scalability, management, and commercial support. You must first install the jruby-ehcache-rails3 gem (version 1.1.0 or later) to use this cache store. If you are using JRuby you can use Terracotta's Ehcache as the cache store for your application. Ehcache is an open source Java cache that also offers an enterprise version with increased scalability, management, and commercial support. You must first install the jruby-ehcache-rails3 gem (version 1.1.0 or later) to use this cache store.


<ruby> <ruby>
ActionController::Base.cache_store = :ehcache_store config.cache_store = :ehcache_store
</ruby> </ruby>


When initializing the cache, you may use the +:ehcache_config+ option to specify the Ehcache config file to use (where the default is "ehcache.xml" in your Rails config directory), and the :cache_name option to provide a custom name for your cache (the default is rails_cache). When initializing the cache, you may use the +:ehcache_config+ option to specify the Ehcache config file to use (where the default is "ehcache.xml" in your Rails config directory), and the :cache_name option to provide a custom name for your cache (the default is rails_cache).
Expand Down Expand Up @@ -359,7 +361,7 @@ h4. ActiveSupport::Cache::NullStore
This cache store implementation is meant to be used only in development or test environments and it never stores anything. This can be very useful in development when you have code that interacts directly with +Rails.cache+, but caching may interfere with being able to see the results of code changes. With this cache store, all +fetch+ and +read+ operations will result in a miss. This cache store implementation is meant to be used only in development or test environments and it never stores anything. This can be very useful in development when you have code that interacts directly with +Rails.cache+, but caching may interfere with being able to see the results of code changes. With this cache store, all +fetch+ and +read+ operations will result in a miss.


<ruby> <ruby>
ActionController::Base.cache_store = :null_store config.cache_store = :null_store
</ruby> </ruby>


h4. Custom Cache Stores h4. Custom Cache Stores
Expand All @@ -369,7 +371,7 @@ You can create your own custom cache store by simply extending +ActiveSupport::C
To use a custom cache store, simple set the cache store to a new instance of the class. To use a custom cache store, simple set the cache store to a new instance of the class.


<ruby> <ruby>
ActionController::Base.cache_store = MyCacheStore.new config.cache_store = MyCacheStore.new
</ruby> </ruby>


h4. Cache Keys h4. Cache Keys
Expand Down
Loading

0 comments on commit 014498e

Please sign in to comment.