public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Merge documentation changes from docrails.

commit 0fc3381aa5359f31b36057d7bfba2e0eb6a3c064
Author: Xavier Noria <fxn@hashref.com>
Date:   Fri May 16 23:44:51 2008 +0200

    Conventions. Formatting. Revising docs all over the rails.

    This revision encourages the modern resource-oriented form_for usage. 
    In addition corrects some markup and other details.

commit 70e4bcf5cb039bea073851faed2df9f465e6f2f8
Author: Chris Kampmeier <chris@kampers.net>
Date:   Fri May 16 12:09:46 2008 -0700

    Fix a couple spelling errors in docs

commit 6ea5e4208f724b50e774e6a1af027336c3ee3de1
Author: Chris O'Sullivan <thechrisoshow@gmail.com>
Date:   Fri May 16 16:09:11 2008 +0100

    Added docs about source_type for has_one association

commit a01a0178be297b0eb62909819a15a01c6b69a841
Author: miloops <miloops@gmail.com>
Date:   Wed May 14 09:22:39 2008 +0000

    Change migration generator USAGE to explain the timestamped migrations 
    behaviour

commit 4e2bc02163aa646ab1304b1b5bec98a7af8927f5
Author: Xavier Noria <fxn@hashref.com>
Date:   Fri May 16 00:43:03 2008 +0200

    minor revision in url_for docs

    Made explicit that RESTful and controller/action styles are not 
    interchangeable, and revised some markup.

commit d6ecce66f4e125531875006eea8022b73fe135b5
Author: Michael Hartl <michael@michaelhartl.com>
Date:   Thu May 15 10:46:40 2008 -0700

    Expanded and updated the link_to documentation

commit b8c46c86f0b785f6afc3c58eeb1b347543f5901e
Author: Cody Fauser <cody@jadedpixel.com>
Date:   Wed May 14 09:10:02 2008 -0400

    Improve and cleanup ActionMailer documentation

commit 9546ee299952c86329c4854f9b3776382c0575ff
Author: Yehuda Katz <wycats@gmail.com>
Date:   Mon May 12 23:41:43 2008 -0700

    Add documentation for Inflector.inflections

commit cbd5db8f5165f013069b02414f9bf762d88f619f
Author: Manik Juneja <mjuneja@manik-junejas-computer.local>
Date:   Mon May 12 23:43:31 2008 +0530

    minor changes in railties/README. Added dbconsole introduction

commit 130a280ddee1f96ccf378b52c17ee742b5e54f4a
Author: Gaurav Sharma <gaurav@norbauer.com>
Date:   Mon May 12 18:00:19 2008 +0530

    adding documentation for cached_attributes

commit 164c9586480f0a02522ea15ec7fb42c6a783a74d
Author: TomK32 <tomk32@tomk32.de>
Date:   Mon May 12 10:59:33 2008 +0200

    proper heading for "Example:"

commit 35634feb474cc55fbc95edeffe98cec241d45f23
Author: Matt Boehlig <thetamind@gmail.com>
Date:   Sun May 11 16:46:07 2008 -0500

    Cleanup whitespace and change_table documentation

commit 80bba28a1a56a0cafeb0fc94659905e88129bc31
Author: Xavier Noria <fxn@hashref.com>
Date:   Sun May 11 02:54:02 2008 +0200

    documented the source annotation extractor

commit e6823bb1650d9b0fea58bd2d355f388961a408b3
Author: Mike Mondragon <mikemondragon@gmail.com>
Date:   Fri May 9 13:49:56 2008 -0700

    Added additional information about processing email with ActionMailer 
    and the strategy one might want to employ to do so.

commit e6afd8b2736364322b673bbdcca3e9b38b6d3da0
Author: Xavier Noria <fxn@hashref.com>
Date:   Thu May 8 23:49:36 2008 +0200

    corrected and completed docs of increment/decrement/toggle in AR::Base

    
commit 2fead68b3192332eee27945ed95a94a64ca73f70
Author: Austin Putman <austin@emmanuel.local>
Date:   Wed May 7 19:35:46 2008 -0700

    Documented class methods on ActionController::Routing.  These are 
    dangerous, and mostly used for testing.

commit f5b84182dbc39bea79c8ee319c688d00fa99f9d1
Author: Teflon Ted <github@rudiment.net>
Date:   Wed May 7 16:08:49 2008 -0400

    Added explanation about errant inflections not being patched in the 
    future in order to avoid breaking legacy applications.

commit 370f4f51722cec49ace17093d29e9ce9e8f15cfb
Author: Sunny Ripert <negatif@gmail.com>
Date:   Wed May 7 14:00:59 2008 +0200

    Applied list conventions in AR::Base

commit 5bd18429f09d44e75191bec42a6db04bd33f3030
Author: Sunny Ripert <negatif@gmail.com>
Date:   Wed May 7 13:53:35 2008 +0200

    Renamed Options list to Attributes list whenever they weren't option 
    hashes in AR::Base

commit 2fa628e34b25166afb49e3afeea87e770ab84256
Author: Xavier Noria <fxn@hashref.com>
Date:   Wed May 7 11:52:33 2008 +0200

    revised details in Exceptions section of AR::Base docs

commit d912bd5672316454457ae83f6e9dda5197beeb6f
Author: Yaroslav Markin <yaroslav@markin.net>
Date:   Wed May 7 13:50:28 2008 +0400

    Add a filter_parameter_logging usage hint to generated 
    ApplicationController.
    This may help to remind the developer to filter sensitive information 
    from application logs.
    Closes #11578

commit f81d771f0657ae8375b84a77a059812cce5d6fd9
Author: Jack Danger Canty <git@6brand.com>
Date:   Tue May 6 23:35:05 2008 -0700

    doc: 
    ActiveRecord::Reflection::AssociationReflection#through_reflection

    Added documentation demonstrating the use of #through_reflection for
    finding intervening reflection objects for HasManyThrough
    and HasOneThrough.

commit ae6b46f00b5b8b2939c6b37ce3329c83de7e71db
Author: Cheah Chu Yeow <chuyeow@gmail.com>
Date:   Wed May 7 13:47:41 2008 +0800

    Document AttributeAssignmentError and MultiparameterAssignmentErrors.

commit 8f463550b597db2156b67733f31aed13487fbc3a
Author: John Barnette <jbarnette@gmail.com>
Date:   Tue May 6 22:46:44 2008 -0700

    Killing/fixing a bunch of outdated language in the AR README.

commit 284a930a93fbee16e25d06392779dbf2f03e9e12
Author: Jonathan Dance <jd@wuputah.com>
Date:   Tue May 6 14:58:26 2008 -0400

    improvements to the page caching docs

commit 9482da621390c874da7c921c8bd6230caae7035a
Author: Sunny Ripert <negatif@gmail.com>
Date:   Mon May 5 18:13:40 2008 +0200

    validates_numericality_of() "integer" option really is 
    "only_integer"

commit e9afd6790a8f530528f6597a7f59bb283be754f6
Author: Sunny Ripert <negatif@gmail.com>
Date:   Mon May 5 12:11:59 2008 +0200

    Harmonized hash notation in AR::Base

commit 67ebf14a91ffd970b582be4ff2991d691a9cf3e1
Author: Sunny Ripert <negatif@gmail.com>
Date:   Mon May 5 12:06:19 2008 +0200

    Turned options into rdoc-lists in AR::Base

commit 0ec7c0a41d889d4e5382b9dff72f1aaba89bf297
Author: Marshall Huss <mwhuss@Macbook.local>
Date:   Sun May 4 23:21:33 2008 -0400

    Added information of how to set element_name in the case the user has 
    a name confliction with an existing model

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
lifo (author)
Fri May 16 15:01:32 -0700 2008
commit  46f30f902fb5e705683dea19ec22179c61e5f208
tree    a733a5c24ba1411968e448185a7097be1151e63a
parent  345f030c5b6c0a28ddde56c80a1112b00d345c79
...
19
20
21
22
23
 
24
25
26
27
28
...
78
79
80
81
 
 
82
83
84
 
 
 
 
85
86
87
88
89
90
91
92
93
94
95
 
 
 
 
 
 
 
96
97
98
...
19
20
21
 
 
22
23
24
25
26
27
...
77
78
79
 
80
81
82
83
84
85
86
87
88
89
90
91
92
 
 
 
 
 
 
 
93
94
95
96
97
98
99
100
101
102
0
@@ -19,8 +19,7 @@
0
     recipients recipient
0
     subject "[Signed up] Welcome #{recipient}"
0
     from "system@loudthinking.com"
0
-
0
- body(:recipient => recipient)
0
+ body :recipient => recipient
0
   end
0
 
0
 The body of the email is created by using an Action View template (regular
0
0
0
@@ -78,21 +77,26 @@
0
     end
0
   end
0
 
0
-This Mailman can be the target for Postfix. In Rails, you would use the runner like this:
0
+This Mailman can be the target for Postfix or other MTAs. In Rails, you would use the runner in the
0
+trivial case like this:
0
 
0
   ./script/runner 'Mailman.receive(STDIN.read)'
0
 
0
+However, invoking Rails in the runner for each mail to be received is very resource intensive. A single
0
+instance of Rails should be run within a daemon if it is going to be utilized to process more than just
0
+a limited number of email.
0
+
0
 == Configuration
0
 
0
 The Base class has the full list of configuration options. Here's an example:
0
 
0
-ActionMailer::Base.smtp_settings = {
0
- :address=>'smtp.yourserver.com', # default: localhost
0
- :port=>'25', # default: 25
0
- :user_name=>'user',
0
- :password=>'pass',
0
- :authentication=>:plain # :plain, :login or :cram_md5
0
-}
0
+ ActionMailer::Base.smtp_settings = {
0
+ :address => 'smtp.yourserver.com', # default: localhost
0
+ :port => '25', # default: 25
0
+ :user_name => 'user',
0
+ :password => 'pass',
0
+ :authentication => :plain # :plain, :login or :cram_md5
0
+ }
0
 
0
 == Dependencies
0
 
...
35
36
37
38
 
39
40
41
...
127
128
129
130
131
132
133
134
 
 
 
 
 
135
136
137
...
145
146
147
 
148
149
150
151
...
167
168
169
170
171
 
 
 
 
172
 
 
 
173
174
175
176
...
209
210
211
212
213
 
 
214
215
216
217
 
 
 
218
219
220
221
222
223
...
226
227
228
229
230
 
 
231
232
233
234
 
 
 
235
236
237
 
238
239
 
240
241
242
...
35
36
37
 
38
39
40
41
...
127
128
129
 
 
 
 
 
130
131
132
133
134
135
136
137
...
145
146
147
148
149
150
151
152
...
168
169
170
 
 
171
172
173
174
175
176
177
178
179
180
181
182
...
215
216
217
 
 
218
219
220
 
 
 
221
222
223
224
225
226
227
228
229
...
232
233
234
 
 
235
236
237
 
 
 
238
239
240
241
242
 
243
244
 
245
246
247
248
0
@@ -35,7 +35,7 @@
0
   # * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
0
   # * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
0
   # * <tt>cc</tt> - Takes one or more email addresses. These addresses will receive a carbon copy of your email. Sets the <tt>Cc:</tt> header.
0
- # * <tt>bcc</tt> - Takes one or more email address. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc</tt> header.
0
+ # * <tt>bcc</tt> - Takes one or more email address. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc:</tt> header.
0
   # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header wil be set by the delivery agent.
0
   # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
0
   # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
0
@@ -127,11 +127,11 @@
0
   #
0
   # class MyMailer < ActionMailer::Base
0
   # def signup_notification(recipient)
0
- # recipients recipient.email_address_with_name
0
- # subject "New account information"
0
- # body "account" => recipient
0
- # from "system@example.com"
0
- # content_type "text/html" # Here's where the magic happens
0
+ # recipients recipient.email_address_with_name
0
+ # subject "New account information"
0
+ # from "system@example.com"
0
+ # body :account => recipient
0
+ # content_type "text/html"
0
   # end
0
   # end
0
   #
0
@@ -145,6 +145,7 @@
0
   # recipients recipient.email_address_with_name
0
   # subject "New account information"
0
   # from "system@example.com"
0
+ # content_type "multipart/alternative"
0
   #
0
   # part :content_type => "text/html",
0
   # :body => render_message("signup-as-html", :account => recipient)
0
0
@@ -167,9 +168,14 @@
0
   # * signup_notification.text.x-yaml.erb
0
   #
0
   # Each would be rendered and added as a separate part to the message,
0
- # with the corresponding content type. The same body hash is passed to
0
- # each template.
0
+ # with the corresponding content type. The content type for the entire
0
+ # message is automatically set to <tt>multipart/alternative</tt>, which indicates
0
+ # that the email contains multiple different representations of the same email
0
+ # body. The same body hash is passed to each template.
0
   #
0
+ # Implicit template rendering is not performed if any attachments or parts have been added to the email.
0
+ # This means that you'll have to manually add each part to the email and set the content type of the email
0
+ # to <tt>multipart/alternative</tt>.
0
   #
0
   # = Attachments
0
   #
0
0
@@ -209,12 +215,12 @@
0
   # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
0
   # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
0
   # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
0
- # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
0
- # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>
0
+ # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
0
+ # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
0
   #
0
- # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method
0
- # * <tt>:location</tt> - The location of the sendmail executable, defaults to "/usr/sbin/sendmail"
0
- # * <tt>:arguments</tt> - The command line arguments
0
+ # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
0
+ # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
0
+ # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
0
   #
0
   # * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
0
   #
0
0
0
0
@@ -226,17 +232,17 @@
0
   # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
0
   # for unit and functional testing.
0
   #
0
- # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
0
- # pick a different charset from inside a method with <tt>@charset</tt>.
0
+ # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
0
+ # pick a different charset from inside a method with +charset+.
0
   # * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
0
- # can also pick a different content type from inside a method with <tt>@content_type</tt>.
0
- # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to "1.0". You
0
- # can also pick a different value from inside a method with <tt>@mime_version</tt>.
0
+ # can also pick a different content type from inside a method with +content_type+.
0
+ # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
0
+ # can also pick a different value from inside a method with +mime_version+.
0
   # * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
0
   # which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to
0
- # ["text/html", "text/enriched", "text/plain"]. Items that appear first in the array have higher priority in the mail client
0
+ # <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
0
   # and appear last in the mime encoded message. You can also pick a different order from inside a method with
0
- # <tt>@implicit_parts_order</tt>.
0
+ # +implicit_parts_order+.
0
   class Base
0
     include AdvAttrAccessor, PartContainer
0
     include ActionController::UrlWriter if Object.const_defined?(:ActionController)
...
92
93
94
95
 
96
97
98
...
92
93
94
 
95
96
97
98
0
@@ -92,7 +92,7 @@
0
       # with the remaining data.
0
       #
0
       # Note that you can define your own XML parameter parser which would allow you to describe multiple entities
0
- # in a single request (i.e., by wrapping them all in a single root note), but if you just go with the flow
0
+ # in a single request (i.e., by wrapping them all in a single root node), but if you just go with the flow
0
       # and accept Rails' defaults, life will be much easier.
0
       #
0
       # If you need to use a MIME type which isn't supported by default, you can register your own handlers in
...
73
74
75
76
77
 
 
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
80
81
82
83
84
 
 
 
 
85
86
87
88
89
90
91
 
 
 
 
 
 
 
 
92
93
94
95
96
 
 
 
 
 
 
97
98
99
 
 
 
100
101
102
103
104
105
...
105
106
107
108
109
 
 
 
110
111
 
 
112
113
114
115
116
117
118
 
 
119
120
121
122
123
 
 
 
 
124
125
126
...
140
141
142
143
 
144
145
146
...
150
151
152
153
 
154
155
156
...
73
74
75
 
 
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
 
 
 
99
100
101
102
103
104
 
 
 
 
 
105
106
107
108
109
110
111
112
113
 
 
 
 
114
115
116
117
118
119
120
 
 
121
122
123
124
125
126
127
128
129
...
129
130
131
 
 
132
133
134
135
 
136
137
138
139
140
141
142
 
 
143
144
145
146
147
 
 
148
149
150
151
152
153
154
...
168
169
170
 
171
172
173
174
...
178
179
180
 
181
182
183
184
0
@@ -73,30 +73,54 @@
0
     # There are also methods for helping to build form tags in link:classes/ActionView/Helpers/FormOptionsHelper.html,
0
     # link:classes/ActionView/Helpers/DateHelper.html, and link:classes/ActionView/Helpers/ActiveRecordHelper.html
0
     module FormHelper
0
- # Creates a form and a scope around a specific model object that is used as a base for questioning about
0
- # values for the fields.
0
+ # Creates a form and a scope around a specific model object that is used as
0
+ # a base for questioning about values for the fields.
0
       #
0
+ # Rails provides succint resource-oriented form generation with +form_for+
0
+ # like this:
0
+ #
0
+ # <% form_for @offer do |f| %>
0
+ # <%= f.label :version, 'Version' %>:
0
+ # <%= f.text_field :version %><br />
0
+ # <%= f.label :author, 'Author' %>:
0
+ # <%= f.text_field :author %><br />
0
+ # <% end %>
0
+ #
0
+ # There, +form_for+ is able to generate the rest of RESTful parameters
0
+ # based on introspection on the record, but to understand what it does we
0
+ # need to dig first into the alternative generic usage it is based upon.
0
+ #
0
+ # === Generic form_for
0
+ #
0
+ # The generic way to call +form_for+ requires a few arguments:
0
+ #
0
       # <% form_for :person, @person, :url => { :action => "update" } do |f| %>
0
       # <%= f.error_messages %>
0
- # First name: <%= f.text_field :first_name %>
0
- # Last name : <%= f.text_field :last_name %>
0
- # Biography : <%= f.text_area :biography %>
0
- # Admin? : <%= f.check_box :admin %>
0
+ # First name: <%= f.text_field :first_name %><br />
0
+ # Last name : <%= f.text_field :last_name %><br />
0
+ # Biography : <%= f.text_area :biography %><br />
0
+ # Admin? : <%= f.check_box :admin %><br />
0
       # <% end %>
0
       #
0
- # Worth noting is that the form_for tag is called in a ERb evaluation block, not an ERb output block. So that's <tt><% %></tt>,
0
- # not <tt><%= %></tt>. Also worth noting is that form_for yields a <tt>form_builder</tt> object, in this example as <tt>f</tt>, which emulates
0
- # the API for the stand-alone FormHelper methods, but without the object name. So instead of <tt>text_field :person, :name</tt>,
0
- # you get away with <tt>f.text_field :name</tt>. Notice that you can even do <tt><%= f.error_messages %></tt> to display the
0
- # error messsages of the model object in question.
0
+ # Worth noting is that the +form_for+ tag is called in a ERb evaluation block,
0
+ # not an ERb output block. So that's <tt><% %></tt>, not <tt><%= %></tt>. Also
0
+ # worth noting is that +form_for+ yields a form builder object, in this
0
+ # example as +f+, which emulates the API for the stand-alone FormHelper
0
+ # methods, but without the object name. So instead of <tt>text_field :person, :name</tt>,
0
+ # you get away with <tt>f.text_field :name</tt>. Notice that you can even do
0
+ # <tt><%= f.error_messages %></tt> to display the error messsages of the model
0
+ # object in question.
0
       #
0
- # Even further, the form_for method allows you to more easily escape the instance variable convention. So while the stand-alone
0
- # approach would require <tt>text_field :person, :name, :object => person</tt>
0
- # to work with local variables instead of instance ones, the form_for calls remain the same. You simply declare once with
0
- # <tt>:person, person</tt> and all subsequent field calls save <tt>:person</tt> and <tt>:object => person</tt>.
0
+ # Even further, the +form_for+ method allows you to more easily escape the
0
+ # instance variable convention. So while the stand-alone approach would require
0
+ # <tt>text_field :person, :name, :object => person</tt> to work with local
0
+ # variables instead of instance ones, the +form_for+ calls remain the same.
0
+ # You simply declare once with <tt>:person, person</tt> and all subsequent
0
+ # field calls save <tt>:person</tt> and <tt>:object => person</tt>.
0
       #
0
- # Also note that form_for doesn't create an exclusive scope. It's still possible to use both the stand-alone FormHelper methods
0
- # and methods from FormTagHelper. For example:
0
+ # Also note that +form_for+ doesn't create an exclusive scope. It's still
0
+ # possible to use both the stand-alone FormHelper methods and methods from
0
+ # FormTagHelper. For example:
0
       #
0
       # <% form_for :person, @person, :url => { :action => "update" } do |f| %>
0
       # First name: <%= f.text_field :first_name %>
0
0
0
0
@@ -105,22 +129,26 @@
0
       # Admin? : <%= check_box_tag "person[admin]", @person.company.admin? %>
0
       # <% end %>
0
       #
0
- # Note: This also works for the methods in FormOptionHelper and DateHelper that are designed to work with an object as base,
0
- # like FormOptionHelper#collection_select and DateHelper#datetime_select.
0
+ # This also works for the methods in FormOptionHelper and DateHelper that are
0
+ # designed to work with an object as base, like FormOptionHelper#collection_select
0
+ # and DateHelper#datetime_select.
0
       #
0
- # HTML attributes for the form tag can be given as <tt>:html => {...}</tt>. For example:
0
+ # HTML attributes for the form tag can be given as <tt>:html => {...}</tt>.
0
+ # For example:
0
       #
0
       # <% form_for :person, @person, :html => {:id => 'person_form'} do |f| %>
0
       # ...
0
       # <% end %>
0
       #
0
- # The above form will then have the <tt>id</tt> attribute with the value </tt>person_form</tt>, which you can then
0
- # style with CSS or manipulate with JavaScript.
0
+ # The above form will then have the +id+ attribute with the value "person_form",
0
+ # which you can then style with CSS or manipulate with JavaScript.
0
       #
0
       # === Relying on record identification
0
       #
0
- # In addition to manually configuring the form_for call, you can also rely on record identification, which will use
0
- # the conventions and named routes of that approach. Examples:
0
+ # As we said above, in addition to manually configuring the +form_for+ call,
0
+ # you can rely on record identification, which will use the conventions and
0
+ # named routes of that approach. This is the preferred way to use +form_for+
0
+ # nowadays:
0
       #
0
       # <% form_for(@post) do |f| %>
0
       # ...
0
@@ -140,7 +168,7 @@
0
       #
0
       # This will expand to be the same as:
0
       #
0
- # <% form_for :post, @post, :url => posts_path, :html => { :class => "new_post", :id => "new_post" } do |f| %>
0
+ # <% form_for :post, Post.new, :url => posts_path, :html => { :class => "new_post", :id => "new_post" } do |f| %>
0
       # ...
0
       # <% end %>
0
       #
0
@@ -150,7 +178,7 @@
0
       # ...
0
       # <% end %>
0
       #
0
- # And for namespaced routes, like admin_post_url:
0
+ # And for namespaced routes, like +admin_post_url+:
0
       #
0
       # <% form_for([:admin, @post]) do |f| %>
0
       # ...
...
120
121
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
124
125
126
127
128
129
130
 
 
131
132
133
 
 
134
135
136
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
 
 
184
185
186
 
 
187
188
189
190
191
0
@@ -120,17 +120,72 @@
0
       # exception.
0
       #
0
       # ==== Examples
0
+ # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments
0
+ # and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
0
+ # your application on resources and use
0
+ #
0
+ # link_to "Profile", profile_path(@profile)
0
+ # # => <a href="/profiles/1">Profile</a>
0
+ #
0
+ # or the even pithier
0
+ #
0
+ # link_to "Profile", @profile
0
+ # # => <a href="/profiles/1">Profile</a>
0
+ #
0
+ # in place of the older more verbose, non-resource-oriented
0
+ #
0
+ # link_to "Profile", :controller => "profiles", :action => "show", :id => @profile
0
+ # # => <a href="/profiles/show/1">Profile</a>
0
+ #
0
+ # Similarly,
0
+ #
0
+ # link_to "Profiles", profiles_path
0
+ # # => <a href="/profiles">Profiles</a>
0
+ #
0
+ # is better than
0
+ #
0
+ # link_to "Profiles", :controller => "profiles"
0
+ # # => <a href="/profiles">Profiles</a>
0
+ #
0
+ # Classes and ids for CSS are easy to produce:
0
+ #
0
+ # link_to "Articles", articles_path, :id => "news", :class => "article"
0
+ # # => <a href="/articles" class="article" id="news">Articles</a>
0
+ #
0
+ # Be careful when using the older argument style, as an extra literal hash is needed:
0
+ #
0
+ # link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article"
0
+ # # => <a href="/articles" class="article" id="news">Articles</a>
0
+ #
0
+ # Leaving the hash off gives the wrong link:
0
+ #
0
+ # link_to "WRONG!", :controller => "articles", :id => "news", :class => "article"
0
+ # # => <a href="/articles/index/news?class=article">WRONG!</a>
0
+ #
0
+ # +link_to+ can also produce links with anchors or query strings:
0
+ #
0
+ # link_to "Comment wall", profile_path(@profile, :anchor => "wall")
0
+ # # => <a href="/profiles/1#wall">Comment wall</a>
0
+ #
0
+ # link_to "Ruby on Rails search", :controller => "searches", :query => "ruby on rails"
0
+ # # => <a href="/searches?query=ruby+on+rails">Ruby on Rails search</a>
0
+ #
0
+ # link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux")
0
+ # # => <a href="/searches?foo=bar&amp;baz=quux">Nonsense search</a>
0
+ #
0
+ # The three options specfic to +link_to+ (<tt>:confirm</tt>, <tt>:popup</tt>, and <tt>:method</tt>) are used as follows:
0
+ #
0
       # link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?"
0
       # # => <a href="http://www.rubyonrails.org/" onclick="return confirm('Are you sure?');">Visit Other Site</a>
0
       #
0
       # link_to "Help", { :action => "help" }, :popup => true
0
       # # => <a href="/testing/help/" onclick="window.open(this.href);return false;">Help</a>
0
       #
0
- # link_to "View Image", { :action => "view" }, :popup => ['new_window_name', 'height=300,width=600']
0
- # # => <a href="/testing/view/" onclick="window.open(this.href,'new_window_name','height=300,width=600');return false;">View Image</a>
0
+ # link_to "View Image", @image, :popup => ['new_window_name', 'height=300,width=600']
0
+ # # => <a href="/images/9" onclick="window.open(this.href,'new_window_name','height=300,width=600');return false;">View Image</a>
0
       #
0
- # link_to "Delete Image", { :action => "delete", :id => @image.id }, :confirm => "Are you sure?", :method => :delete
0
- # # => <a href="/testing/delete/9/" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form');
0
+ # link_to "Delete Image", @image, :confirm => "Are you sure?", :method => :delete
0
+ # # => <a href="/images/9" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form');
0
       # f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
0
       # var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
0
       # m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete Image</a>
...
12
13
14
15
 
16
17
18
...
12
13
14
 
15
16
17
18
0
@@ -12,7 +12,7 @@
0
 
0
     change_table :videos do |t|
0
       t.timestamps # adds created_at, updated_at
0
- t.belongs_to :goat # add goat_id integer
0
+ t.belongs_to :goat # adds goat_id integer
0
       t.string :name, :email, :limit => 20 # adds name and email both with a 20 char limit
0
       t.remove :name, :email # removes the name and email columns
0
     end
...
753
754
755
 
 
756
757
758
...
753
754
755
756
757
758
759
760
0
@@ -753,6 +753,8 @@
0
       # * <tt>:source</tt> - Specifies the source association name used by <tt>has_one :through</tt> queries. Only use it if the name cannot be
0
       # inferred from the association. <tt>has_one :favorite, :through => :favorites</tt> will look for a
0
       # <tt>:favorite</tt> on Favorite, unless a <tt>:source</tt> is given.
0
+ # * <tt>:source_type</tt> - Specifies type of the source association used by <tt>has_one :through</tt> queries where the source
0
+ # association is a polymorphic +belongs_to+.
0
       # * <tt>:readonly</tt> - If true, the associated object is readonly through the association.
0
       #
0
       # Option examples:
...
16
17
18
19
20
 
 
 
21
 
22
 
23
24
25
26
 
 
27
28
 
29
30
31
...
60
61
62
63
64
 
 
65
66
67
...
89
90
91
92
93
 
 
 
94
95
96
97
98
...
104
105
106
107
 
108
109
110
111
112
 
 
113
114
115
116
117
 
118
119
120
121
122
...
210
211
212
213
 
214
215
216
217
 
218
219
220
 
221
222
223
...
288
289
290
291
 
292
293
294
...
319
320
321
322
323
 
 
 
324
325
326
...
16
17
18
 
 
19
20
21
22
23
24
25
26
27
 
 
28
29
30
31
32
33
34
35
...
64
65
66
 
 
67
68
69
70
71
...
93
94
95
 
 
96
97
98
99
100
101
102
103
...
109
110
111
 
112
113
114
115
116
 
117
118
119
120
121
122
123
124
125
126
127
128
129
...
217
218
219
 
220
221
222
223
 
224
225
226
 
227
228
229
230
...
295
296
297
 
298
299
300
301
...
326
327
328
 
 
329
330
331
332
333
334
0
@@ -16,16 +16,20 @@
0
 
0
     # Declare and check for suffixed attribute methods.
0
     module ClassMethods
0
- # Declare a method available for all attributes with the given suffix.
0
- # Uses method_missing and respond_to? to rewrite the method
0
+ # Declares a method available for all attributes with the given suffix.
0
+ # Uses +method_missing+ and <tt>respond_to?</tt> to rewrite the method
0
+ #
0
       # #{attr}#{suffix}(*args, &block)
0
+ #
0
       # to
0
+ #
0
       # attribute#{suffix}(#{attr}, *args, &block)
0
       #
0
- # An attribute#{suffix} instance method must exist and accept at least
0
- # the attr argument.
0
+ # An <tt>attribute#{suffix}</tt> instance method must exist and accept at least
0
+ # the +attr+ argument.
0
       #
0
       # For example:
0
+ #
0
       # class Person < ActiveRecord::Base
0
       # attribute_method_suffix '_changed?'
0
       #
0
@@ -60,8 +64,8 @@
0
         !generated_methods.empty?
0
       end
0
       
0
- # generates all the attribute related methods for columns in the database
0
- # accessors, mutators and query methods
0
+ # Generates all the attribute related methods for columns in the database
0
+ # accessors, mutators and query methods.
0
       def define_attribute_methods
0
         return if generated_methods?
0
         columns_hash.each do |name, column|
0
@@ -89,8 +93,9 @@
0
         end
0
       end
0
 
0
- # Check to see if the method is defined in the model or any of its subclasses that also derive from ActiveRecord.
0
- # Raise DangerousAttributeError if the method is defined by ActiveRecord though.
0
+ # Checks whether the method is defined in the model or any of its subclasses
0
+ # that also derive from ActiveRecord. Raises DangerousAttributeError if the
0
+ # method is defined by Active Record though.
0
       def instance_method_already_implemented?(method_name)
0
         method_name = method_name.to_s
0
         return true if method_name =~ /^id(=$|\?$|$)/
0
0
0
@@ -104,17 +109,19 @@
0
 
0
       # +cache_attributes+ allows you to declare which converted attribute values should
0
       # be cached. Usually caching only pays off for attributes with expensive conversion
0
- # methods, like date columns (e.g. created_at, updated_at).
0
+ # methods, like time related columns (e.g. +created_at+, +updated_at+).
0
       def cache_attributes(*attribute_names)
0
         attribute_names.each {|attr| cached_attributes << attr.to_s}
0
       end
0
 
0
- # returns the attributes where
0
+ # Returns the attributes which are cached. By default time related columns
0
+ # with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached.
0
       def cached_attributes
0
         @cached_attributes ||=
0
           columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map(&:name).to_set
0
       end
0
 
0
+ # Returns +true+ if the provided attribute is being cached.
0
       def cache_attribute?(attr_name)
0
         cached_attributes.include?(attr_name)
0
       end
0
0
0
@@ -210,14 +217,14 @@
0
     end # ClassMethods
0
 
0
 
0
- # Allows access to the object attributes, which are held in the @attributes hash, as though they
0
+ # Allows access to the object attributes, which are held in the <tt>@attributes</tt> hash, as though they
0
     # were first-class methods. So a Person class with a name attribute can use Person#name and
0
     # Person#name= and never directly use the attributes hash -- except for multiple assigns with
0
     # ActiveRecord#attributes=. A Milestone class can also ask Milestone#completed? to test that
0
- # the completed attribute is not nil or 0.
0
+ # the completed attribute is not +nil+ or 0.
0
     #
0
     # It's also possible to instantiate related objects, so a Client class belonging to the clients
0
- # table with a master_id foreign key can instantiate master through Client#master.
0
+ # table with a +master_id+ foreign key can instantiate master through Client#master.
0
&nbs