diff options
Diffstat (limited to 'railties')
7 files changed, 173 insertions, 15 deletions
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 9476635ae6..db0b431eb9 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -137,9 +137,9 @@ Hence, if the method name starts with +deliver_+ followed by any combination of h4. Complete List of Action Mailer User-Settable Attributes -|bcc| The BCC addresses of the email| +|bcc| The BCC addresses of the email, either as a string (for a single address) or an array of strings (for multiple addresses)| |body| The body of the email. This is either a hash (in which case it specifies the variables to pass to the template when it is rendered), or a string, in which case it specifies the actual body of the message| -|cc| The CC addresses for the email| +|cc| The CC addresses for the email, either as a string (for a single address) or an array of strings (for multiple addresses)| |charset| The charset to use for the email. This defaults to the +default_charset+ specified for ActionMailer::Base.| |content_type| The content type for the email. This defaults to "text/plain" but the filename may specify it| |from| The from address of the email| @@ -264,9 +264,9 @@ end h4. Sending Multipart Emails with Attachments -Once you use the +attachment+ method, ActionMailer will no longer automagically use the correct template based on the filename. You must declare which template you are using for each content type via the +part+ method. +Once you use the +attachment+ method, ActionMailer will no longer automagically use the correct template based on the filename, nor will it properly order the alternative parts. You must declare which template you are using for each content type via the +part+ method. And you must declare these templates in the proper order. -In the following example, there would be two template files, +welcome_email_html.erb+ and +welcome_email_plain.erb+ in the +app/views/user_mailer+ folder. +In the following example, there would be two template files, +welcome_email_html.erb+ and +welcome_email_plain.erb+ in the +app/views/user_mailer+ folder. The +text/plain+ part must be listed first for full compatibility with email clients. If +text/plain+ is listed after +text/html+, some clients may display both the HTML and plain text versions of the email. The text alternatives alone must be enclosed in a +multipart/alternative+ part. Do not set the entire message's +content_type+ to +multipart/alternative+ or some email clients may ignore the display of attachments such as PDF's. <ruby> class UserMailer < ActionMailer::Base @@ -274,14 +274,15 @@ class UserMailer < ActionMailer::Base recipients user.email_address subject "New account information" from "system@example.com" - content_type "multipart/alternative" - part "text/html" do |p| - p.body = render_message("welcome_email_html", :message => "<h1>HTML content</h1>") - end + part "multipart/alternative" do |pt| + pt.part "text/plain" do |p| + p.body = render_message("welcome_email_plain", :message => "text content") + end - part "text/plain" do |p| - p.body = render_message("welcome_email_plain", :message => "text content") + pt.part "text/html" do |p| + p.body = render_message("welcome_email_html", :message => "<h1>HTML content</h1>") + end end attachment :content_type => "image/jpeg", diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index b112c4f5fb..1b1d9a8009 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -6,7 +6,6 @@ This guide covers different ways to retrieve data from the database using Active * Specify the order, retrieved attributes, grouping, and other properties of the found records * Use eager loading to reduce the number of database queries needed for data retrieval * Use dynamic finders methods -* Create named scopes to add custom finding behavior to your models * Check for the existence of particular records * Perform various calculations on Active Record models diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile new file mode 100644 index 0000000000..2130d18491 --- /dev/null +++ b/railties/guides/source/active_support_overview.textile @@ -0,0 +1,132 @@ +h2. Active Support Overview + +Active Support is the Rails component responsible for providing Ruby language extensions, utilities, and other transversal stuff. It offers a richer bottom-line at the language level, targeted both at the development of Rails applications, and at the development of Rails itself. + +By referring to this guide you will learn: + +* The extensions to the Ruby core modules and classes provided by Rails. +* The rest of fundamental libraries available in Rails. + +endprologue. + +h3. Extensions to +Kernel+ + +... + +h3. Extensions to +Object+ + +... + +h3. Extensions to +Module+ + +... + +h3. Extensions to +Class+ + +... + +h3. Extensions to +NilClass+ + +... + +h3. Extensions to +TrueClass+ + +... + +h3. Extensions to +FalseClass+ + +... + +h3. Extensions to +Symbol+ + +... + +h3. Extensions to +String+ + +... + +h3. Extensions to +Numeric+ + +... + +h3. Extensions to +Integer+ + +... + +h3. Extensions to +Float+ + +... + +h3. Extensions to +BigDecimal+ + +... + +h3. Extensions to +Enumerable+ + +... + +h3. Extensions to +Array+ + +... + +h3. Extensions to +Hash+ + +... + +h3. Extensions to +Range+ + +... + +h3. Extensions to +Proc+ + +... + +h3. Extensions to +Date+ + +... + +h3. Extensions to +DateTime+ + +... + +h3. Extensions to +Time+ + +... + +h3. Extensions to +Process+ + +... + +h3. Extensions to +Pathname+ + +... + +h3. Extensions to +File+ + +... + +h3. Extensions to +Exception+ + +... + +h3. Extensions to +NameError+ + +... + +h3. Extensions to +LoadError+ + +... + +h3. Extensions to +CGI+ + +... + +h3. Extensions to +Benchmark+ + +... + +h3. Changelog + +"Lighthouse ticket":https://rails.lighthouseapp.com/projects/16213/tickets/67 + +* April 18, 2009: Initial version by "Xavier Noria":credits.html#fxn diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile index 5ae4884297..218125e35f 100644 --- a/railties/guides/source/activerecord_validations_callbacks.textile +++ b/railties/guides/source/activerecord_validations_callbacks.textile @@ -530,11 +530,11 @@ class Invoice < ActiveRecord::Base end </ruby> -You can even create your own validation helpers and reuse them in several different models. Here is an example where we create a custom validation helper to validate the format of fields that represent email addresses: +You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find useful to express that a certain field corresponds to a set of choices: <ruby> ActiveRecord::Base.class_eval do - def self.validates_as_radio(attr_name, n, options={}) + def self.validates_as_choice(attr_name, n, options={}) validates_inclusion_of attr_name, {:in => 1..n}.merge(options) end end @@ -544,7 +544,7 @@ Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd ty <ruby> class Movie < ActiveRecord::Base - validates_as_radio :rating, 5 + validates_as_choice :rating, 5 end </ruby> diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 03e22bd6fe..4d75fb6dc4 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -600,6 +600,7 @@ The +belongs_to+ association supports these options: * +:polymorphic+ * +:readonly+ * +:select+ +* +:touch+ * +:validate+ h6. +:autosave+ @@ -736,6 +737,28 @@ The +:select+ option lets you override the SQL +SELECT+ clause that is used to r TIP: If you set the +:select+ option on a +belongs_to+ association, you should also set the +foreign_key+ option to guarantee the correct results. +h6. +:touch+ + +If you set the +:touch+ option to +:true+, then the +updated_at+ or +updated_on+ timestamp on the associated object will be set to the current time whenever this object is saved or destroyed: + +<ruby> +class Order < ActiveRecord::Base + belongs_to :customer, :touch => true +end + +class Customer < ActiveRecord::Base + has_many :orders +end +</ruby> + +In this case, saving or destroying an order will update the timestamp on the associated customer. You can also specify a particular timestamp attribute to update: + +<ruby> +class Order < ActiveRecord::Base + belongs_to :customer, :touch => :orders_updated_at +end +</ruby> + h6. +:validate+ If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved. @@ -1775,6 +1798,7 @@ h3. Changelog "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/11 +* April 19, 2009: Added +:touch+ option to +belongs_to+ associations by "Mike Gunderloy":credits.html#mgunderloy * February 1, 2009: Added +:autosave+ option "Mike Gunderloy":credits.html#mgunderloy * September 28, 2008: Corrected +has_many :through+ diagram, added polymorphic diagram, some reorganization by "Mike Gunderloy":credits.html#mgunderloy . First release version. * September 22, 2008: Added diagrams, misc. cleanup by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication) diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 5ed94c30b7..bcea5e0cb5 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -78,7 +78,7 @@ Active Record provides methods that perform common data definition tasks in a da If you need to perform tasks specific to your database (for example create a "foreign key":#active-record-and-referential-integrity constraint) then the +execute+ function allows you to execute arbitrary SQL. A migration is just a regular Ruby class so you're not limited to these functions. For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models). -On databases that support transactions with statements that change the schema (such as PostgreSQL), migrations are wrapped in a transaction. If the database does not support this (for example MySQL and SQLite) then when a migration fails the parts of it that succeeded will not be rolled back. You will have to unpick the changes that were made by hand. +On databases that support transactions with statements that change the schema (such as PostgreSQL or SQLite3), migrations are wrapped in a transaction. If the database does not support this (for example MySQL) then when a migration fails the parts of it that succeeded will not be rolled back. You will have to unpick the changes that were made by hand. h4. What's in a Name diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index 12fc836edf..1776c77927 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -413,6 +413,8 @@ h4. Rails Specific Assertions Rails adds some custom assertions of its own to the +test/unit+ framework: +NOTE: +assert_valid(record)+ has been deprecated. Please use +assert(record.valid?)+ instead. + |_.Assertion |_.Purpose| |+assert_valid(record)+ |Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.| |+assert_difference(expressions, difference = 1, message = nil) {...}+ |Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.| |