From cb02d10df2b892925bfa8b2a9b01223e44f2acb4 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Mon, 25 Jul 2011 15:10:13 -0700
Subject: sync the getting started guide with master
---
railties/guides/source/getting_started.textile | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 0b89021392..6c8aa668b2 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -197,9 +197,10 @@ For example, the following HTTP request:
DELETE /photos/17
-refers to a photo resource with an ID of 17 and indicates an action to be taken
-upon it: deletion. REST is a natural web application architecture which Rails
-abstracts, shielding you from RESTful complexities and browser quirks.
+would be understood to refer to a photo resource with the ID of 17, and to
+indicate a desired action - deleting that resource. REST is a natural style for
+the architecture of web applications, and Rails hooks into this shielding you
+from many of the RESTful complexities and browser quirks.
If you'd like more details on REST as an architectural style, these resources
are more approachable than Fielding's thesis:
--
cgit v1.2.3
From fa159d317611d1fe5b483f2542666da00bab2e6c Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 26 Jul 2011 19:35:16 +0530
Subject: move the note after the scaffold files listing
---
railties/guides/source/getting_started.textile | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 6c8aa668b2..3cca383616 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -536,21 +536,8 @@ command in your terminal:
$ rails generate scaffold Post name:string title:string content:text
-This will create a new database table called posts (plural of Post). The table
-will have three columns, name (type string), title (type string) and content
-(type text). It will also hook this new database up to Rails (details below).
-
-NOTE. While scaffolding will get you up and running quickly, the code it
-generates is unlikely to be a perfect fit for your application. You'll most
-probably want to customize the generated code. Many experienced Rails developers
-avoid scaffolding entirely, preferring to write all or most of their source code
-from scratch. Rails, however, makes it really simple to customize templates for
-generated models, controllers, views and other source files. You'll find more
-information in the "Creating and Customizing Rails Generators &
-Templates":generators.html guide.
-
-The scaffold generator will build 17 files in your application, along with some
-folders, and edit one more. Here's a quick overview of what it creates:
+The scaffold generator will build several files in your application, along with some
+folders, and edit config/routes.rb. Here's a quick overview of what it creates:
|_.File |_.Purpose|
|db/migrate/20100207214725_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp)|
@@ -571,6 +558,15 @@ folders, and edit one more. Here's a quick overview of what it creates:
|test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper|
|config/routes.rb |Edited to include routing information for posts|
+NOTE. While scaffolding will get you up and running quickly, the code it
+generates is unlikely to be a perfect fit for your application. You'll most
+probably want to customize the generated code. Many experienced Rails developers
+avoid scaffolding entirely, preferring to write all or most of their source code
+from scratch. Rails, however, makes it really simple to customize templates for
+generated models, controllers, views and other source files. You'll find more
+information in the "Creating and Customizing Rails Generators &
+Templates":generators.html guide.
+
h4. Running a Migration
One of the products of the +rails generate scaffold+ command is a _database
--
cgit v1.2.3
From 5a22f05522d4b624463da174576f3663ea2872ac Mon Sep 17 00:00:00 2001
From: Alberto Perdomo
Date: Thu, 28 Jul 2011 00:51:14 +0100
Subject: Association and Callbacks guide: Added section on shortcut syntax
'validates'.
---
.../active_record_validations_callbacks.textile | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index ce0b5416de..e2ec874190 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -612,6 +612,61 @@ class Movie < ActiveRecord::Base
end
+h3. Shortcut helper
+
+There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+.
+
+h4. Multiple validations for a single attribue
+
+In cases where you want multiple validations for a single attribute you can do it with a one-liner.
+
+
+class User < ActiveRecord::Base
+ validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 }
+end
+
+
+h4. Combining standard validations with custom validators
+
+You can also combine standard validations with your own custom validators.
+
+
+class EmailValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ record.errors[attribute] << (options[:message] || "is not an email") unless
+ value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ end
+end
+
+class Person
+ include ActiveModel::Validations
+ attr_accessor :name, :email
+
+ validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 }
+ validates :email, :presence => true, :email => true
+end
+
+
+h4. Validating multiple attributes with the same criteria
+
+If you have a case where you want to apply the same validations to multiple attributes you can do that as well.
+
+
+class BlogPost < ActiveRecord::Base
+ validates :title, :body, :presence => true
+end
+
+
+h4. Using the standard options
+
+The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+.
+
+
+class User < ActiveRecord::Base
+ validates :password, :presence => { :if => :password_required? }, :confirmation => true
+end
+
+
h3. Working with Validation Errors
In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects.
--
cgit v1.2.3
From 4265f2eaa50b9783059bc84c3f8d2d4001fa9b7a Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Mon, 25 Jul 2011 15:10:13 -0700
Subject: sync the getting started guide with master
---
railties/guides/source/getting_started.textile | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 0b89021392..6c8aa668b2 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -197,9 +197,10 @@ For example, the following HTTP request:
DELETE /photos/17
-refers to a photo resource with an ID of 17 and indicates an action to be taken
-upon it: deletion. REST is a natural web application architecture which Rails
-abstracts, shielding you from RESTful complexities and browser quirks.
+would be understood to refer to a photo resource with the ID of 17, and to
+indicate a desired action - deleting that resource. REST is a natural style for
+the architecture of web applications, and Rails hooks into this shielding you
+from many of the RESTful complexities and browser quirks.
If you'd like more details on REST as an architectural style, these resources
are more approachable than Fielding's thesis:
--
cgit v1.2.3
From 2dc6cca773380e55d2afe0d3de34fa7c68f9f7d7 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 26 Jul 2011 19:35:16 +0530
Subject: move the note after the scaffold files listing
---
railties/guides/source/getting_started.textile | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 6c8aa668b2..3cca383616 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -536,21 +536,8 @@ command in your terminal:
$ rails generate scaffold Post name:string title:string content:text
-This will create a new database table called posts (plural of Post). The table
-will have three columns, name (type string), title (type string) and content
-(type text). It will also hook this new database up to Rails (details below).
-
-NOTE. While scaffolding will get you up and running quickly, the code it
-generates is unlikely to be a perfect fit for your application. You'll most
-probably want to customize the generated code. Many experienced Rails developers
-avoid scaffolding entirely, preferring to write all or most of their source code
-from scratch. Rails, however, makes it really simple to customize templates for
-generated models, controllers, views and other source files. You'll find more
-information in the "Creating and Customizing Rails Generators &
-Templates":generators.html guide.
-
-The scaffold generator will build 17 files in your application, along with some
-folders, and edit one more. Here's a quick overview of what it creates:
+The scaffold generator will build several files in your application, along with some
+folders, and edit config/routes.rb. Here's a quick overview of what it creates:
|_.File |_.Purpose|
|db/migrate/20100207214725_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp)|
@@ -571,6 +558,15 @@ folders, and edit one more. Here's a quick overview of what it creates:
|test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper|
|config/routes.rb |Edited to include routing information for posts|
+NOTE. While scaffolding will get you up and running quickly, the code it
+generates is unlikely to be a perfect fit for your application. You'll most
+probably want to customize the generated code. Many experienced Rails developers
+avoid scaffolding entirely, preferring to write all or most of their source code
+from scratch. Rails, however, makes it really simple to customize templates for
+generated models, controllers, views and other source files. You'll find more
+information in the "Creating and Customizing Rails Generators &
+Templates":generators.html guide.
+
h4. Running a Migration
One of the products of the +rails generate scaffold+ command is a _database
--
cgit v1.2.3
From e84ea65e71062109d9e95e36ea0c5640fb0d6d6f Mon Sep 17 00:00:00 2001
From: Alberto Perdomo
Date: Thu, 28 Jul 2011 00:51:14 +0100
Subject: Association and Callbacks guide: Added section on shortcut syntax
'validates'.
---
.../active_record_validations_callbacks.textile | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index ce0b5416de..e2ec874190 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -612,6 +612,61 @@ class Movie < ActiveRecord::Base
end
+h3. Shortcut helper
+
+There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+.
+
+h4. Multiple validations for a single attribue
+
+In cases where you want multiple validations for a single attribute you can do it with a one-liner.
+
+
+class User < ActiveRecord::Base
+ validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 }
+end
+
+
+h4. Combining standard validations with custom validators
+
+You can also combine standard validations with your own custom validators.
+
+
+class EmailValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ record.errors[attribute] << (options[:message] || "is not an email") unless
+ value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ end
+end
+
+class Person
+ include ActiveModel::Validations
+ attr_accessor :name, :email
+
+ validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 }
+ validates :email, :presence => true, :email => true
+end
+
+
+h4. Validating multiple attributes with the same criteria
+
+If you have a case where you want to apply the same validations to multiple attributes you can do that as well.
+
+
+class BlogPost < ActiveRecord::Base
+ validates :title, :body, :presence => true
+end
+
+
+h4. Using the standard options
+
+The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+.
+
+
+class User < ActiveRecord::Base
+ validates :password, :presence => { :if => :password_required? }, :confirmation => true
+end
+
+
h3. Working with Validation Errors
In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects.
--
cgit v1.2.3
From 60af023107c8b11e2a07b8950d9fea8849fe2c32 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Fri, 19 Aug 2011 09:47:46 +0000
Subject: Extra "l" removed before h2.
---
railties/guides/source/i18n.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 0c8e4e974d..5a6343472c 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -1,4 +1,4 @@
-lh2. Rails Internationalization (I18n) API
+h2. Rails Internationalization (I18n) API
The Ruby I18n (shorthand for _internationalization_) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for *translating your application to a single custom language* other than English or for *providing multi-language support* in your application.
--
cgit v1.2.3
From f56c2b88c58c33643050551c6824dfbf2b7b421e Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:19:43 +0530
Subject: Active Resouce guide initial load
---
railties/guides/source/active_resource_basics.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 railties/guides/source/active_resource_basics.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
new file mode 100644
index 0000000000..5df8b6612d
--- /dev/null
+++ b/railties/guides/source/active_resource_basics.textile
@@ -0,0 +1,11 @@
+h2. Active Resource Basics
+
+This guide should provide you with all you need to get started managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.
+
+endprologue.
+
+WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.
+
+h3. Changelog
+
+* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From e898556543fbfcbaeed88420590d555c857315cc Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:21:21 +0530
Subject: Introduction for active resource
---
railties/guides/source/active_resource_basics.textile | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 5df8b6612d..5cf22f8e39 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -6,6 +6,10 @@ endprologue.
WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.
+h3. Introduction
+
+Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+.
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 8d1c642cae05cbf4c4fa44b9f7afb7c7a3727bd3 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:23:05 +0530
Subject: configuration for active resource
---
railties/guides/source/active_resource_basics.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 5cf22f8e39..f0cd25bfc2 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -10,6 +10,17 @@ h3. Introduction
Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+.
+h3. Configuration and Usage
+
+Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class
+that inherits from ActiveResource::Base and providing a site class variable to it:
+
+
+class Person < ActiveResource::Base
+ self.site = "http://api.people.com:3000/"
+end
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From c62cb2f2fbbd7987a4e09e9ffd63b60560785e6f Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:24:18 +0530
Subject: usages of active resouce
---
railties/guides/source/active_resource_basics.textile | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index f0cd25bfc2..64f0949475 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -21,6 +21,15 @@ class Person < ActiveResource::Base
end
+Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes
+life cycle methods that operate against a persistent store.
+
+
+# Find a person with id = 1
+ryan = Person.find(1)
+Person.exists?(1) # => true
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 29772a136a6f148f3cc27ddfccc29bd9ddc672e3 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 30 Jul 2011 23:50:31 +0530
Subject: remove some parts of the section on shortcut helpers, document custom
validators
---
.../active_record_validations_callbacks.textile | 104 +++++++++------------
1 file changed, 45 insertions(+), 59 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index e2ec874190..5789d36c6d 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -569,101 +569,87 @@ end
All validations inside of +with_options+ block will have automatically passed the condition +:if => :is_admin?+
-h3. Creating Custom Validation Methods
+h3. Performing Custom Validations
-When the built-in validation helpers are not enough for your needs, you can write your own validation methods.
+When the built-in validation helpers are not enough for your needs, you can write your own validators or validation methods as you prefer.
-Simply create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names.
+h4. Custom Validators
-You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered.
+Custom validators are classes that extend ActiveModel::Validator. These classes must implement a +validate+ method which takes a record as an argument and performs the validation on it. The custom validator is called using the +validates_with+ method.
-class Invoice < ActiveRecord::Base
- validate :expiration_date_cannot_be_in_the_past,
- :discount_cannot_be_greater_than_total_value
-
- def expiration_date_cannot_be_in_the_past
- errors.add(:expiration_date, "can't be in the past") if
- !expiration_date.blank? and expiration_date < Date.today
+class MyValidator < ActiveModel::Validator
+ def validate(record)
+ if record.name.starts_with? 'X'
+ record.errors[:name] << 'Need a name starting with X please!'
+ end
end
+end
- def discount_cannot_be_greater_than_total_value
- errors.add(:discount, "can't be greater than total value") if
- discount > total_value
- end
+class Person
+ include ActiveModel::Validations
+ validates_with MyValidator
end
-You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices:
+The easiest way to add custom validators for validating individual attributes is with the convenient ActiveModel::EachValidator. In this case, the custom validator class must implement a +validate_each+ method which takes three arguments: record, attribute and value which correspond to the instance, the attribute to be validated and the value of the attribute in the passed instance.
-ActiveRecord::Base.class_eval do
- def self.validates_as_choice(attr_name, n, options={})
- validates attr_name, :inclusion => { {:in => 1..n}.merge(options) }
+class EmailValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ record.errors[attribute] << (options[:message] || "is not an email")
+ end
end
end
-
-
-Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this:
-
-class Movie < ActiveRecord::Base
- validates_as_choice :rating, 5
+class Person < ActiveRecord::Base
+ validates :email, :presence => true, :email => true
end
-h3. Shortcut helper
+As shown in the example, you can also combine standard validations with your own custom validators.
-There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+.
+h4. Custom Methods
-h4. Multiple validations for a single attribue
+You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names.
-In cases where you want multiple validations for a single attribute you can do it with a one-liner.
+You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered.
-class User < ActiveRecord::Base
- validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 }
-end
-
-
-h4. Combining standard validations with custom validators
-
-You can also combine standard validations with your own custom validators.
+class Invoice < ActiveRecord::Base
+ validate :expiration_date_cannot_be_in_the_past,
+ :discount_cannot_be_greater_than_total_value
-
-class EmailValidator < ActiveModel::EachValidator
- def validate_each(record, attribute, value)
- record.errors[attribute] << (options[:message] || "is not an email") unless
- value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ def expiration_date_cannot_be_in_the_past
+ if !expiration_date.blank? and expiration_date < Date.today
+ errors.add(:expiration_date, "can't be in the past")
+ end
end
-end
-
-class Person
- include ActiveModel::Validations
- attr_accessor :name, :email
- validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 }
- validates :email, :presence => true, :email => true
+ def discount_cannot_be_greater_than_total_value
+ if discount > total_value
+ errors.add(:discount, "can't be greater than total value")
+ end
+ end
end
-h4. Validating multiple attributes with the same criteria
-
-If you have a case where you want to apply the same validations to multiple attributes you can do that as well.
+You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices:
-class BlogPost < ActiveRecord::Base
- validates :title, :body, :presence => true
+ActiveRecord::Base.class_eval do
+ def self.validates_as_choice(attr_name, n, options={})
+ validates attr_name, :inclusion => { {:in => 1..n}.merge(options) }
+ end
end
-h4. Using the standard options
-
-The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+.
+Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this:
-class User < ActiveRecord::Base
- validates :password, :presence => { :if => :password_required? }, :confirmation => true
+class Movie < ActiveRecord::Base
+ validates_as_choice :rating, 5
end
--
cgit v1.2.3
From 54e7694982510e22810c064ae3594f74209c94b9 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 30 Jul 2011 23:53:11 +0530
Subject: prefer to use if..end unless the condition is simple/compact
---
.../guides/source/active_record_validations_callbacks.textile | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 5789d36c6d..977e736d25 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -1143,8 +1143,9 @@ Here's an example where we create a class with an +after_destroy+ callback for a
class PictureFileCallbacks
def after_destroy(picture_file)
- File.delete(picture_file.filepath)
- if File.exists?(picture_file.filepath)
+ if File.exists?(picture_file.filepath)
+ File.delete(picture_file.filepath)
+ end
end
end
@@ -1162,8 +1163,9 @@ Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we
class PictureFileCallbacks
def self.after_destroy(picture_file)
- File.delete(picture_file.filepath)
- if File.exists?(picture_file.filepath)
+ if File.exists?(picture_file.filepath)
+ File.delete(picture_file.filepath)
+ end
end
end
--
cgit v1.2.3
From 4e28c40bfd16a1d9f41c8c713f2b4cc19d5dd1f7 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 31 Jul 2011 01:32:20 +0530
Subject: 3.1 release notes draft
---
railties/guides/source/3_1_release_notes.textile | 136 +++++++++++++++++++++++
1 file changed, 136 insertions(+)
create mode 100644 railties/guides/source/3_1_release_notes.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
new file mode 100644
index 0000000000..0348259668
--- /dev/null
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -0,0 +1,136 @@
+h2. Ruby on Rails 3.1 Release Notes
+
+Highlights in Rails 3.1:
+
+* Streaming
+* Reversible Migrations
+* Assets Pipeline
+* jQuery as the default JavaScript library
+
+This release notes cover the major changes, but don't include every little bug fix and change. If you want to see everything, check out the "list of commits":https://github.com/rails/rails/commits/master in the main Rails repository on GitHub.
+
+endprologue.
+
+h3. Upgrading to Rails 3.1
+
+If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes:
+
+h4. Rails 3.1 requires at least Ruby 1.8.7
+
+Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.1 is also compatible with Ruby 1.9.2.
+
+TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing.
+
+TODO. What else?
+
+h3. Creating a Rails 3.1 application
+
+
+# You should have the 'rails' rubygem installed
+$ rails new myapp
+$ cd myapp
+
+
+h4. Vendoring Gems
+
+Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
+
+More information: - "bundler homepage":http://gembundler.com
+
+h4. Living on the Edge
+
++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag:
+
+
+$ rails new myapp --edge
+
+
+If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the +--dev+ flag:
+
+
+$ ruby /path/to/rails/bin/rails new myapp --dev
+
+
+h3. Rails Architectural Changes
+
+h4. Assets Pipeline
+
+h3. Documentation
+
+The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
+
+More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects.
+
+h3. Internationalization
+
+h3. Railties
+
+h3. Action Pack
+
+h4. Abstract Controller
+
+h4. Action Controller
+
+h4. Action Dispatch
+
+h4. Action View
+
+h3. Active Record
+
+h3. Active Model
+
+The major changes in Active Model are:
+
+* +attr_accessible+ accepts an option +:as+ to specify a role.
+
+* +InclusionValidator+, +ExclusionValidator+, and +FormatValidator+ now accepts an option which can be a proc, a lambda, or anything that respond to +call+. This option will be called with the current record as an argument and returns an object which respond to +include?+ for +InclusionValidator+ and +ExclusionValidator+, and returns a regular expression object for +FormatValidator+.
+
+* Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting.
+
+* ActiveModel::AttributeMethods allows attributes to be defined on demand.
+
+h3. Active Resource
+
+The changes in Active Resource are:
+
+* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example,
+
+
+class User < ActiveResource::Base
+ self.format = :xml
+end
+
+
+h3. Active Support
+
+The main changes in Active Support are:
+
+* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant.
+
+* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR.
+
+* Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object.
+
+* Added Object#in? to test if an object is included in another object.
+
+* LocalCache strategy is now a real middleware class and no longer an anonymous class.
+
+* ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes.
+
+* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache.
+
+* Backports Range#cover? as an alias for Range#include? in Ruby 1.8.
+
+* Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time.
+
+* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants!
+
+Deprecations:
+
+* ActiveSupport::SecureRandom is deprecated in favor of +SecureRandom+ from the Ruby standard library.
+
+h3. Credits
+
+See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.
+
+Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev.
--
cgit v1.2.3
From fe6b967aea0c562a5bcae54225dbce29013991b9 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 31 Jul 2011 03:05:24 +0530
Subject: 3.1 release notes - added AP and Railties sections
---
railties/guides/source/3_1_release_notes.textile | 142 +++++++++++++++++++++++
1 file changed, 142 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 0348259668..f520e4dfea 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -55,6 +55,8 @@ h3. Rails Architectural Changes
h4. Assets Pipeline
+TODO. point to assets guide, talk about rake assets:* tasks
+
h3. Documentation
The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
@@ -65,8 +67,148 @@ h3. Internationalization
h3. Railties
+* jQuery is the new default JavaScript library.
+
+* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems.
+
+* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline.
+
+* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified.
+
+* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available.
+
+* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, --old-style-hash can be passed.
+
+* Scaffold controller generator creates format block for JSON instead of XML.
+
+* Active Record logging is directed to STDOUT and shown inline in the console.
+
+* Added +config.force_ssl+ configuration which loads Rack::SSL middleware and force all requests to be under HTTPS protocol.
+
+* Added +rails plugin new+ command which generates a Rails plugin with gemspec, tests and a dummy application for testing.
+
+* Added Rack::Etag and Rack::ConditionalGet to the default middleware stack.
+
+* Added Rack::Cache to the default middleware stack.
+
+* TODO Engine related changes
+
h3. Action Pack
+TODO split items into controller/view sections.
+
+* A warning is given out if the CSRF token authenticity cannot be verified.
+
+* Allows AM/PM format in datetime selectors.
+
+* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
+
+* Added streaming support, you can enable it with:
+
+
+class PostsController < ActionController::Base
+ stream :only => :index
+end
+
+
+Please read the docs at ActionController::Streaming for more information. TODO add links to api docs.
+
+* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers.
+
+* Created ActionView::Renderer and specified an API for ActionView::Context.
+
+* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+
+* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call.
+
+
+class PostsController < ApplicationController
+ USER_NAME, PASSWORD = "dhh", "secret"
+
+ before_filter :authenticate, :except => [ :index ]
+
+ def index
+ render :text => "Everyone can see me!"
+ end
+
+ def edit
+ render :text => "I'm only accessible if you know the password"
+ end
+
+ private
+ def authenticate
+ authenticate_or_request_with_http_basic do |user_name, password|
+ user_name == USER_NAME && password == PASSWORD
+ end
+ end
+end
+
+
+..can now be written as
+
+
+class PostsController < ApplicationController
+ http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
+
+ def index
+ render :text => "Everyone can see me!"
+ end
+
+ def edit
+ render :text => "I'm only accessible if you know the password"
+ end
+end
+
+
+* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used.
+
+* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete })
+
+* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
+
+* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log.
+
+* URL parameters which return nil for +to_param+ are now removed from the query string.
+
+* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array.
+
+* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false.
+
+* Added HTML5 button_tag helper.
+
+* Template lookup now searches further up in the inheritance chain.
+
+* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version?
+
+* url_for and named url helpers now accept :subdomain and :domain as options.
+
+* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused.
+
+* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
+
+* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options:
+
+
+tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)})
+# =>
+
+
+Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
+
+* The old template handler API is deprecated and the new API simply requires a template handler to respond to call.
+
+* rhtml and rxml are finally removed as template handlers.
+
+* Moved etag responsibility from ActionDispatch::Response to the middleware stack.
+
+* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy.
+
+* file_field automatically adds :multipart => true to the enclosing form.
+
+* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility.
+
+* Added Rack::Cache to the default stack.
+
h4. Abstract Controller
h4. Action Controller
--
cgit v1.2.3
From 8362b070dc959a11042afc9a9a5a8529178c4090 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 31 Jul 2011 16:56:40 +0530
Subject: Rack::Sendfile is no more default middleware.
---
railties/guides/source/command_line.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index b34506d4d8..627e22f2de 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -386,7 +386,7 @@ Action Pack version 3.1.0
Active Resource version 3.1.0
Action Mailer version 3.1.0
Active Support version 3.1.0
-Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
+Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
Application root /home/foobar/commandsapp
Environment development
--
cgit v1.2.3
From f63599825b440e214c09646501be33933d265562 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 31 Jul 2011 21:58:59 +0530
Subject: Adding more info as rake about is fixed
---
railties/guides/source/command_line.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index 627e22f2de..f48fa96451 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -389,6 +389,8 @@ Active Support version 3.1.0
Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
Application root /home/foobar/commandsapp
Environment development
+Database adapter sqlite3
+Database schema version 0
h4. +assets+
--
cgit v1.2.3
From 05f6135895d74f9058f550e6ece4593d2b6501fe Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 31 Jul 2011 23:23:25 +0530
Subject: 3.1 release notes Active Record changes, Architectural changes and
organizing sections.
---
railties/guides/source/3_1_release_notes.textile | 189 ++++++++++++++++++++---
1 file changed, 165 insertions(+), 24 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index f520e4dfea..7d85d7a600 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -55,15 +55,23 @@ h3. Rails Architectural Changes
h4. Assets Pipeline
-TODO. point to assets guide, talk about rake assets:* tasks
+The major change in Rails 3.1 is the Assets Pipeline. It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines.
-h3. Documentation
+The assets pipeline is powered by "Sprockets":https://github.com/sstephenson/sprockets and is covered in the "Asset Pipeline":asset_pipeline.html guide.
-The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
+h4. HTTP Streaming
-More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects.
+HTTP Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it.
-h3. Internationalization
+h4. Default JS library is now jQuery
+
+jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch.
+
+h4. Identity Map
+
+Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion.
+
+Rails 3.1 comes with the identity map turned off by default.
h3. Railties
@@ -95,13 +103,9 @@ h3. Railties
h3. Action Pack
-TODO split items into controller/view sections.
-
-* A warning is given out if the CSRF token authenticity cannot be verified.
-
-* Allows AM/PM format in datetime selectors.
+h4. Abstract Controller
-* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
+h4. Action Controller
* Added streaming support, you can enable it with:
@@ -111,13 +115,25 @@ class PostsController < ActionController::Base
end
-Please read the docs at ActionController::Streaming for more information. TODO add links to api docs.
+Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
+
+* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+
+h4. Action Dispatch
* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers.
+h4. Action View
+
* Created ActionView::Renderer and specified an API for ActionView::Context.
-* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+TODO
+
+* A warning is given out if the CSRF token authenticity cannot be verified.
+
+* Allows AM/PM format in datetime selectors.
+
+* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call.
@@ -209,19 +225,148 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
* Added Rack::Cache to the default stack.
-h4. Abstract Controller
+h3. Active Record
-h4. Action Controller
+* Added a class method pluralize_table_names to singularize/pluralize table names of individual models. Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names.
+
+class User < ActiveRecord::Base
+ self.pluralize_table_names = false
+end
+
-h4. Action Dispatch
+* Added block setting of attributes to singular associations. The block will get called after the instance is initialized.
-h4. Action View
+
+class User < ActiveRecord::Base
+ has_one :account
+end
-h3. Active Record
+user.build_account{ |a| a.credit_limit => 100.0 }
+
-h3. Active Model
+* Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist.
+
+* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0
+
+* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities:
+
+
+class Post < ActiveRecord::Base
+ attr_accessible :title
+ attr_accessible :title, :published_at, :as => :admin
+end
+
+Post.new(params[:post], :as => :admin)
+
+
+* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation:
+
+* Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped.
+
+* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
+
+* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed.
+
+* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records.
+
+* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations.
+
+* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config.
-The major changes in Active Model are:
+* limits and offsets are removed from COUNT queries unless both are supplied.
+
+People.limit(1).count # => 'SELECT COUNT(*) FROM people'
+People.offset(1).count # => 'SELECT COUNT(*) FROM people'
+People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
+
+
+* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings.
+
+* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead.
+
+* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
+
+* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'.
+
+* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table.
+
+* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table.
+
+* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy)
+
+* Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement.
+
+
+change_table(:users, :bulk => true) do |t|
+ t.string :company_name
+ t.change :birthdate, :datetime
+end
+
+
+* Removed support for accessing attributes on a +has_and_belongs_to_many+ join table. has_many :through needs to be used.
+
+* Added a +create_association!+ method for +has_one+ and +belongs_to+ associations.
+
+* Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations. To use reversible migrations, just define the +change+ method.
+
+class MyMigration < ActiveRecord::Migration
+ def change
+ create_table(:horses) do
+ t.column :content, :text
+ t.column :remind_at, :datetime
+ end
+ end
+end
+
+
+* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down.
+
+* Migrations now use instance methods rather than class methods:
+
+class FooMigration < ActiveRecord::Migration
+ def up # Not self.up
+ ...
+ end
+end
+
+
+* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods.
+
+* Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used.
+
+
+has_many :things, :conditions => 'foo = #{bar}' # before
+has_many :things, :conditions => proc { "foo = #{bar}" } # after
+
+
+Inside the proc, 'self' is the object which is the owner of the association, unless you are eager loading the association, in which case 'self' is the class which the association is within.
+
+You can have any "normal" conditions inside the proc, so the following will work too:
+
+has_many :things, :conditions => proc { ["foo = ?", bar] }
+
+
+* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc.
+
+* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting.
+
+# Schema: User(name:string, password_digest:string, password_salt:string)
+class User < ActiveRecord::Base
+ has_secure_password
+end
+
+
+* When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns.
+
+* Setting the id of a belongs_to object will update the reference to the object.
+
+* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics.
+
+* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called.
+
+* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable.
+
+h3. Active Model
* +attr_accessible+ accepts an option +:as+ to specify a role.
@@ -233,8 +378,6 @@ The major changes in Active Model are:
h3. Active Resource
-The changes in Active Resource are:
-
* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example,
@@ -245,8 +388,6 @@ end
h3. Active Support
-The main changes in Active Support are:
-
* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant.
* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR.
--
cgit v1.2.3
From abfbab2713211dc6094165a1bb74fde5c17c2a74 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 20:37:42 +0530
Subject: Active Resource - guide for reading and writing data
---
railties/guides/source/active_resource_basics.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 64f0949475..8a36622814 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -24,10 +24,21 @@ end
Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes
life cycle methods that operate against a persistent store.
+h3. Reading and Writing Data
+
+Active Resource make request over HTTP using a standard JSON format. It mirrors the RESTful routing built into Action Controller but will also work with any other REST service that properly implements the protocol.
+
+h4. Read
+
+Read requests use the GET method and expect the JSON form of whatever resource/resources is/are being requested.
+
# Find a person with id = 1
ryan = Person.find(1)
+# Check if a person exists with id = 1
Person.exists?(1) # => true
+# Get all resources of Person class
+Person.all
h3. Changelog
--
cgit v1.2.3
From 163533b17d968d23eef0023e4c93338d5357d022 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 20:48:45 +0530
Subject: Active Resource - guide for create
---
railties/guides/source/active_resource_basics.textile | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 8a36622814..e40ca4fc42 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -34,13 +34,22 @@ Read requests use the GET method and expect the JSON form of whatever resource/r
# Find a person with id = 1
-ryan = Person.find(1)
+person = Person.find(1)
# Check if a person exists with id = 1
Person.exists?(1) # => true
# Get all resources of Person class
Person.all
+h4. Create
+
+Creating a new resource submits the JSON form of the resource as the body of the request with HTTP POST method and parse the response into Active Resource object.
+
+
+person = Person.create(:name => 'Vishnu')
+person.id # => 1
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From eed1026e83e04aef4c455a15636dab2e0e28efe3 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 20:57:57 +0530
Subject: Active Resource - guide for update/save
---
railties/guides/source/active_resource_basics.textile | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index e40ca4fc42..1115b9848f 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -50,6 +50,16 @@ person = Person.create(:name => 'Vishnu')
person.id # => 1
+h4. Update
+
+To update an existing resource, 'save' method is used. This method make a HTTP PUT request in JSON format.
+
+
+person = Person.find(1)
+person.name = 'Atrai'
+person.save
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From f3564b9e22ae318dadee6c21c52aba01f91b27bb Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 21:02:48 +0530
Subject: Active Resource - guide for destroy
---
railties/guides/source/active_resource_basics.textile | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 1115b9848f..332d113fa7 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -60,6 +60,15 @@ person.name = 'Atrai'
person.save
+h4. Delete
+
+'destroy' method makes a HTTP DELETE request for an existing resource in JSON format to delete that resource.
+
+
+person = Person.find(1)
+person.destroy
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 9e1a27a0ac4ef246079ac6f61f5b5916c68d0497 Mon Sep 17 00:00:00 2001
From: pbflinn
Date: Mon, 1 Aug 2011 12:53:43 -0300
Subject: Fix typo 'console' -> 'constant'
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 477ee5a3a2..9b92edd250 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -71,7 +71,7 @@ module Rails
end
-The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ console, we'll see that when we get to the +in_rails_application?+ method.
+The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method.
Back in +rails/cli+, the next line is this:
--
cgit v1.2.3
From b3719ee7ed4693c782087c56c2ba5984a473deb7 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 3 Aug 2011 19:11:22 +0530
Subject: fixed incorrect tags
---
railties/guides/source/migrations.textile | 32 +++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index e51ee0f535..7b501807d6 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -477,7 +477,7 @@ Several methods are provided that allow you to control all this:
For example, this migration
-
+
class CreateProducts < ActiveRecord::Migration
def change
suppress_messages do
@@ -496,7 +496,7 @@ class CreateProducts < ActiveRecord::Migration
end
end
end
-
+
generates the following output
@@ -525,7 +525,7 @@ Bob goes on vacation.
Alice creates a migration for the +products+ table which adds a new column and initializes it.
She also adds a validation to the Product model for the new column.
-
+
# db/migrate/20100513121110_add_flag_to_product.rb
class AddFlagToProduct < ActiveRecord::Migration
@@ -534,19 +534,19 @@ class AddFlagToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes!(:flag => 'false') }
end
end
-
+
-
+
# app/model/product.rb
class Product < ActiveRecord::Base
validates_presence_of :flag
end
-
+
Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column.
-
+
# db/migrate/20100515121110_add_fuzz_to_product.rb
class AddFuzzToProduct < ActiveRecord::Migration
@@ -555,16 +555,16 @@ class AddFuzzToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
end
end
-
+
-
+
# app/model/product.rb
class Product < ActiveRecord::Base
validates_presence_of :flag
validates_presence_of :fuzz
end
-
+
Both migrations work for Alice.
@@ -575,12 +575,12 @@ Bob comes back from vacation and:
The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs.
-
+
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `fuzz' for #
-
+
A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion.
@@ -588,7 +588,7 @@ When using a faux model, it's a good idea to call +Product.reset_column_informat
If Alice had done this instead, there would have been no problem:
-
+
# db/migrate/20100513121110_add_flag_to_product.rb
class AddFlagToProduct < ActiveRecord::Migration
@@ -600,9 +600,9 @@ class AddFlagToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes!(:flag => false) }
end
end
-
+
-
+
# db/migrate/20100515121110_add_fuzz_to_product.rb
class AddFuzzToProduct < ActiveRecord::Migration
@@ -614,7 +614,7 @@ class AddFuzzToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
end
end
-
+
h3. Schema Dumping and You
--
cgit v1.2.3
From febdd6c96c827b8faee22ba9d15c1d943a70a6d3 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 3 Aug 2011 19:13:12 +0530
Subject: minor changes in migrations guide
---
railties/guides/source/migrations.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 7b501807d6..4476e067a6 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -540,7 +540,7 @@ end
# app/model/product.rb
class Product < ActiveRecord::Base
- validates_presence_of :flag
+ validates :flag, :presence => true
end
@@ -561,8 +561,7 @@ end
# app/model/product.rb
class Product < ActiveRecord::Base
- validates_presence_of :flag
- validates_presence_of :fuzz
+ validates :flag, :fuzz, :presence => true
end
@@ -594,9 +593,10 @@ If Alice had done this instead, there would have been no problem:
class AddFlagToProduct < ActiveRecord::Migration
class Product < ActiveRecord::Base
end
+
def change
add_column :products, :flag, :int
- Product.reset_column_information
+ Product.reset_column_information
Product.all.each { |f| f.update_attributes!(:flag => false) }
end
end
--
cgit v1.2.3
From 25845b3d42c899749913d948f952f332e275fd26 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 3 Aug 2011 19:34:23 +0530
Subject: typo fix
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 9b92edd250..6ab2706d6b 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -33,7 +33,7 @@ end
This file will attempt to load +rails/cli+ and if it cannot find it then add the +railties/lib+ path to the load path (+$:+) and will then try to require it again.
-h4. +railites/lib/rails/cli.rb+
+h4. +railties/lib/rails/cli.rb+
This file looks like this:
--
cgit v1.2.3
From 2e764c5fd1ae4757da2cd834ca310f3eeb8db3e0 Mon Sep 17 00:00:00 2001
From: JudeArasu
Date: Wed, 3 Aug 2011 23:00:24 +0530
Subject: grammatical changes
---
railties/guides/source/form_helpers.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index bf2a7369a7..fa0ca5827a 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex
h4. A Generic Search Form
-One of the most basic forms you see on the web is a search form. This form contains:
+One of the most basic forms you will see on the web is a search form. This form contains:
# a form element with "GET" method,
# a label for the input,
@@ -807,3 +807,4 @@ h3. Authors
* Mislav Marohnić
* "Frederick Cheung":credits.html#fcheung
+
--
cgit v1.2.3
From e82b4901eb8f5f3582a079e88c75a4fbc7dea767 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Thu, 4 Aug 2011 15:02:13 -0700
Subject: Revert "grammatical changes"
Reason: As discussed in GitHub, it is debatable, and present tense
is fine (and simple, and preferred).
This reverts commit 54ccda9f0a5e4a5e72a4c159dc8787faaf65e8a2.
---
railties/guides/source/form_helpers.textile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index fa0ca5827a..bf2a7369a7 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex
h4. A Generic Search Form
-One of the most basic forms you will see on the web is a search form. This form contains:
+One of the most basic forms you see on the web is a search form. This form contains:
# a form element with "GET" method,
# a label for the input,
@@ -807,4 +807,3 @@ h3. Authors
* Mislav Marohnić
* "Frederick Cheung":credits.html#fcheung
-
--
cgit v1.2.3
From e746980507ed48e30ab35daf587bf9863d5b9261 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Sun, 7 Aug 2011 16:20:31 -0700
Subject: guides generation: apparently this workaround for RedCloth is not
needed anymore
---
railties/guides/rails_guides/generator.rb | 48 ++--------------------
railties/guides/rails_guides/textile_extensions.rb | 25 +++++++++--
2 files changed, 26 insertions(+), 47 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb
index d304512ff7..4682ead66e 100644
--- a/railties/guides/rails_guides/generator.rb
+++ b/railties/guides/rails_guides/generator.rb
@@ -199,50 +199,10 @@ module RailsGuides
end
def textile(body, lite_mode=false)
- # If the issue with notextile is fixed just remove the wrapper.
- with_workaround_for_notextile(body) do |body|
- t = RedCloth.new(body)
- t.hard_breaks = false
- t.lite_mode = lite_mode
- t.to_html(:notestuff, :plusplus, :code)
- end
- end
-
- # For some reason the notextile tag does not always turn off textile. See
- # LH ticket of the security guide (#7). As a temporary workaround we deal
- # with code blocks by hand.
- def with_workaround_for_notextile(body)
- code_blocks = []
-
- body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)\1>}m) do |m|
- brush = case $1
- when 'ruby', 'sql', 'plain'
- $1
- when 'erb'
- 'ruby; html-script: true'
- when 'html'
- 'xml' # html is understood, but there are .xml rules in the CSS
- else
- 'plain'
- end
-
- code_blocks.push(<
-
-
-#{ERB::Util.h($2).strip}
-
-
-
-HTML
- "\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n"
- end
-
- body = yield body
-
- body.gsub(%r{
dirty_workaround_for_notextile_(\d+)
}) do |_|
- code_blocks[$1.to_i]
- end
+ t = RedCloth.new(body)
+ t.hard_breaks = false
+ t.lite_mode = lite_mode
+ t.to_html(:notestuff, :plusplus, :code)
end
def warn_about_broken_links(html)
diff --git a/railties/guides/rails_guides/textile_extensions.rb b/railties/guides/rails_guides/textile_extensions.rb
index b3e0e32357..4677fae504 100644
--- a/railties/guides/rails_guides/textile_extensions.rb
+++ b/railties/guides/rails_guides/textile_extensions.rb
@@ -33,11 +33,30 @@ module RailsGuides
body.gsub!('', '+')
end
+ def brush_for(code_type)
+ case code_type
+ when 'ruby', 'sql', 'plain'
+ code_type
+ when 'erb'
+ 'ruby; html-script: true'
+ when 'html'
+ 'xml' # html is understood, but there are .xml rules in the CSS
+ else
+ 'plain'
+ end
+ end
+
def code(body)
body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)\1>}m) do |m|
- es = ERB::Util.h($2)
- css_class = $1.in?(['erb', 'shell']) ? 'html' : $1
- %{
#{es}
}
+ <
+
+
+#{ERB::Util.h($2).strip}
+
+
+
+HTML
end
end
end
--
cgit v1.2.3
From 2177282262195f9decf564b237304a6ff94c3048 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:19:43 +0530
Subject: Active Resouce guide initial load
---
railties/guides/source/active_resource_basics.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 railties/guides/source/active_resource_basics.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
new file mode 100644
index 0000000000..5df8b6612d
--- /dev/null
+++ b/railties/guides/source/active_resource_basics.textile
@@ -0,0 +1,11 @@
+h2. Active Resource Basics
+
+This guide should provide you with all you need to get started managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.
+
+endprologue.
+
+WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.
+
+h3. Changelog
+
+* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 5da1ddb7506d4dc1b314f6634e4c28e13e6eeaa2 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:21:21 +0530
Subject: Introduction for active resource
---
railties/guides/source/active_resource_basics.textile | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 5df8b6612d..5cf22f8e39 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -6,6 +6,10 @@ endprologue.
WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.
+h3. Introduction
+
+Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+.
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 95c2230f0577c8f3ef2312fe9268dc9c0ed3bf8a Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:23:05 +0530
Subject: configuration for active resource
---
railties/guides/source/active_resource_basics.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 5cf22f8e39..f0cd25bfc2 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -10,6 +10,17 @@ h3. Introduction
Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+.
+h3. Configuration and Usage
+
+Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class
+that inherits from ActiveResource::Base and providing a site class variable to it:
+
+
+class Person < ActiveResource::Base
+ self.site = "http://api.people.com:3000/"
+end
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From ad55b1aa86a1d8b7d6e9e35c7cce77b122bca1e1 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Sat, 30 Jul 2011 18:24:18 +0530
Subject: usages of active resouce
---
railties/guides/source/active_resource_basics.textile | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index f0cd25bfc2..64f0949475 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -21,6 +21,15 @@ class Person < ActiveResource::Base
end
+Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes
+life cycle methods that operate against a persistent store.
+
+
+# Find a person with id = 1
+ryan = Person.find(1)
+Person.exists?(1) # => true
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 225a2482c19fa3a1acdc05371a44b090c6cb4d7c Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 30 Jul 2011 23:50:31 +0530
Subject: remove some parts of the section on shortcut helpers, document custom
validators
---
.../active_record_validations_callbacks.textile | 104 +++++++++------------
1 file changed, 45 insertions(+), 59 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index e2ec874190..5789d36c6d 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -569,101 +569,87 @@ end
All validations inside of +with_options+ block will have automatically passed the condition +:if => :is_admin?+
-h3. Creating Custom Validation Methods
+h3. Performing Custom Validations
-When the built-in validation helpers are not enough for your needs, you can write your own validation methods.
+When the built-in validation helpers are not enough for your needs, you can write your own validators or validation methods as you prefer.
-Simply create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names.
+h4. Custom Validators
-You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered.
+Custom validators are classes that extend ActiveModel::Validator. These classes must implement a +validate+ method which takes a record as an argument and performs the validation on it. The custom validator is called using the +validates_with+ method.
-class Invoice < ActiveRecord::Base
- validate :expiration_date_cannot_be_in_the_past,
- :discount_cannot_be_greater_than_total_value
-
- def expiration_date_cannot_be_in_the_past
- errors.add(:expiration_date, "can't be in the past") if
- !expiration_date.blank? and expiration_date < Date.today
+class MyValidator < ActiveModel::Validator
+ def validate(record)
+ if record.name.starts_with? 'X'
+ record.errors[:name] << 'Need a name starting with X please!'
+ end
end
+end
- def discount_cannot_be_greater_than_total_value
- errors.add(:discount, "can't be greater than total value") if
- discount > total_value
- end
+class Person
+ include ActiveModel::Validations
+ validates_with MyValidator
end
-You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices:
+The easiest way to add custom validators for validating individual attributes is with the convenient ActiveModel::EachValidator. In this case, the custom validator class must implement a +validate_each+ method which takes three arguments: record, attribute and value which correspond to the instance, the attribute to be validated and the value of the attribute in the passed instance.
-ActiveRecord::Base.class_eval do
- def self.validates_as_choice(attr_name, n, options={})
- validates attr_name, :inclusion => { {:in => 1..n}.merge(options) }
+class EmailValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ record.errors[attribute] << (options[:message] || "is not an email")
+ end
end
end
-
-
-Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this:
-
-class Movie < ActiveRecord::Base
- validates_as_choice :rating, 5
+class Person < ActiveRecord::Base
+ validates :email, :presence => true, :email => true
end
-h3. Shortcut helper
+As shown in the example, you can also combine standard validations with your own custom validators.
-There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+.
+h4. Custom Methods
-h4. Multiple validations for a single attribue
+You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names.
-In cases where you want multiple validations for a single attribute you can do it with a one-liner.
+You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered.
-class User < ActiveRecord::Base
- validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 }
-end
-
-
-h4. Combining standard validations with custom validators
-
-You can also combine standard validations with your own custom validators.
+class Invoice < ActiveRecord::Base
+ validate :expiration_date_cannot_be_in_the_past,
+ :discount_cannot_be_greater_than_total_value
-
-class EmailValidator < ActiveModel::EachValidator
- def validate_each(record, attribute, value)
- record.errors[attribute] << (options[:message] || "is not an email") unless
- value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ def expiration_date_cannot_be_in_the_past
+ if !expiration_date.blank? and expiration_date < Date.today
+ errors.add(:expiration_date, "can't be in the past")
+ end
end
-end
-
-class Person
- include ActiveModel::Validations
- attr_accessor :name, :email
- validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 }
- validates :email, :presence => true, :email => true
+ def discount_cannot_be_greater_than_total_value
+ if discount > total_value
+ errors.add(:discount, "can't be greater than total value")
+ end
+ end
end
-h4. Validating multiple attributes with the same criteria
-
-If you have a case where you want to apply the same validations to multiple attributes you can do that as well.
+You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices:
-class BlogPost < ActiveRecord::Base
- validates :title, :body, :presence => true
+ActiveRecord::Base.class_eval do
+ def self.validates_as_choice(attr_name, n, options={})
+ validates attr_name, :inclusion => { {:in => 1..n}.merge(options) }
+ end
end
-h4. Using the standard options
-
-The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+.
+Simply reopen +ActiveRecord::Base+ and define a class method like that. You'd typically put this code somewhere in +config/initializers+. You can use this helper like this:
-class User < ActiveRecord::Base
- validates :password, :presence => { :if => :password_required? }, :confirmation => true
+class Movie < ActiveRecord::Base
+ validates_as_choice :rating, 5
end
--
cgit v1.2.3
From ad9e52f156575f28949837a3dd0fa433fa824d57 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 30 Jul 2011 23:53:11 +0530
Subject: prefer to use if..end unless the condition is simple/compact
---
.../guides/source/active_record_validations_callbacks.textile | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 5789d36c6d..977e736d25 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -1143,8 +1143,9 @@ Here's an example where we create a class with an +after_destroy+ callback for a
class PictureFileCallbacks
def after_destroy(picture_file)
- File.delete(picture_file.filepath)
- if File.exists?(picture_file.filepath)
+ if File.exists?(picture_file.filepath)
+ File.delete(picture_file.filepath)
+ end
end
end
@@ -1162,8 +1163,9 @@ Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we
class PictureFileCallbacks
def self.after_destroy(picture_file)
- File.delete(picture_file.filepath)
- if File.exists?(picture_file.filepath)
+ if File.exists?(picture_file.filepath)
+ File.delete(picture_file.filepath)
+ end
end
end
--
cgit v1.2.3
From ebbf010d4d3f1001ccd6e22e417109135652cafb Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 31 Jul 2011 01:32:20 +0530
Subject: 3.1 release notes draft
---
railties/guides/source/3_1_release_notes.textile | 136 +++++++++++++++++++++++
1 file changed, 136 insertions(+)
create mode 100644 railties/guides/source/3_1_release_notes.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
new file mode 100644
index 0000000000..0348259668
--- /dev/null
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -0,0 +1,136 @@
+h2. Ruby on Rails 3.1 Release Notes
+
+Highlights in Rails 3.1:
+
+* Streaming
+* Reversible Migrations
+* Assets Pipeline
+* jQuery as the default JavaScript library
+
+This release notes cover the major changes, but don't include every little bug fix and change. If you want to see everything, check out the "list of commits":https://github.com/rails/rails/commits/master in the main Rails repository on GitHub.
+
+endprologue.
+
+h3. Upgrading to Rails 3.1
+
+If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes:
+
+h4. Rails 3.1 requires at least Ruby 1.8.7
+
+Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.1 is also compatible with Ruby 1.9.2.
+
+TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing.
+
+TODO. What else?
+
+h3. Creating a Rails 3.1 application
+
+
+# You should have the 'rails' rubygem installed
+$ rails new myapp
+$ cd myapp
+
+
+h4. Vendoring Gems
+
+Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
+
+More information: - "bundler homepage":http://gembundler.com
+
+h4. Living on the Edge
+
++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag:
+
+
+$ rails new myapp --edge
+
+
+If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the +--dev+ flag:
+
+
+$ ruby /path/to/rails/bin/rails new myapp --dev
+
+
+h3. Rails Architectural Changes
+
+h4. Assets Pipeline
+
+h3. Documentation
+
+The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
+
+More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects.
+
+h3. Internationalization
+
+h3. Railties
+
+h3. Action Pack
+
+h4. Abstract Controller
+
+h4. Action Controller
+
+h4. Action Dispatch
+
+h4. Action View
+
+h3. Active Record
+
+h3. Active Model
+
+The major changes in Active Model are:
+
+* +attr_accessible+ accepts an option +:as+ to specify a role.
+
+* +InclusionValidator+, +ExclusionValidator+, and +FormatValidator+ now accepts an option which can be a proc, a lambda, or anything that respond to +call+. This option will be called with the current record as an argument and returns an object which respond to +include?+ for +InclusionValidator+ and +ExclusionValidator+, and returns a regular expression object for +FormatValidator+.
+
+* Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting.
+
+* ActiveModel::AttributeMethods allows attributes to be defined on demand.
+
+h3. Active Resource
+
+The changes in Active Resource are:
+
+* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example,
+
+
+class User < ActiveResource::Base
+ self.format = :xml
+end
+
+
+h3. Active Support
+
+The main changes in Active Support are:
+
+* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant.
+
+* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR.
+
+* Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object.
+
+* Added Object#in? to test if an object is included in another object.
+
+* LocalCache strategy is now a real middleware class and no longer an anonymous class.
+
+* ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes.
+
+* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache.
+
+* Backports Range#cover? as an alias for Range#include? in Ruby 1.8.
+
+* Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time.
+
+* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants!
+
+Deprecations:
+
+* ActiveSupport::SecureRandom is deprecated in favor of +SecureRandom+ from the Ruby standard library.
+
+h3. Credits
+
+See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.
+
+Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev.
--
cgit v1.2.3
From f40723996453470c2b00ff49a25282e0f8bbd691 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 31 Jul 2011 03:05:24 +0530
Subject: 3.1 release notes - added AP and Railties sections
---
railties/guides/source/3_1_release_notes.textile | 142 +++++++++++++++++++++++
1 file changed, 142 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 0348259668..f520e4dfea 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -55,6 +55,8 @@ h3. Rails Architectural Changes
h4. Assets Pipeline
+TODO. point to assets guide, talk about rake assets:* tasks
+
h3. Documentation
The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
@@ -65,8 +67,148 @@ h3. Internationalization
h3. Railties
+* jQuery is the new default JavaScript library.
+
+* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems.
+
+* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline.
+
+* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified.
+
+* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available.
+
+* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, --old-style-hash can be passed.
+
+* Scaffold controller generator creates format block for JSON instead of XML.
+
+* Active Record logging is directed to STDOUT and shown inline in the console.
+
+* Added +config.force_ssl+ configuration which loads Rack::SSL middleware and force all requests to be under HTTPS protocol.
+
+* Added +rails plugin new+ command which generates a Rails plugin with gemspec, tests and a dummy application for testing.
+
+* Added Rack::Etag and Rack::ConditionalGet to the default middleware stack.
+
+* Added Rack::Cache to the default middleware stack.
+
+* TODO Engine related changes
+
h3. Action Pack
+TODO split items into controller/view sections.
+
+* A warning is given out if the CSRF token authenticity cannot be verified.
+
+* Allows AM/PM format in datetime selectors.
+
+* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
+
+* Added streaming support, you can enable it with:
+
+
+class PostsController < ActionController::Base
+ stream :only => :index
+end
+
+
+Please read the docs at ActionController::Streaming for more information. TODO add links to api docs.
+
+* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers.
+
+* Created ActionView::Renderer and specified an API for ActionView::Context.
+
+* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+
+* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call.
+
+
+class PostsController < ApplicationController
+ USER_NAME, PASSWORD = "dhh", "secret"
+
+ before_filter :authenticate, :except => [ :index ]
+
+ def index
+ render :text => "Everyone can see me!"
+ end
+
+ def edit
+ render :text => "I'm only accessible if you know the password"
+ end
+
+ private
+ def authenticate
+ authenticate_or_request_with_http_basic do |user_name, password|
+ user_name == USER_NAME && password == PASSWORD
+ end
+ end
+end
+
+
+..can now be written as
+
+
+class PostsController < ApplicationController
+ http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
+
+ def index
+ render :text => "Everyone can see me!"
+ end
+
+ def edit
+ render :text => "I'm only accessible if you know the password"
+ end
+end
+
+
+* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used.
+
+* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete })
+
+* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
+
+* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log.
+
+* URL parameters which return nil for +to_param+ are now removed from the query string.
+
+* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array.
+
+* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false.
+
+* Added HTML5 button_tag helper.
+
+* Template lookup now searches further up in the inheritance chain.
+
+* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version?
+
+* url_for and named url helpers now accept :subdomain and :domain as options.
+
+* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused.
+
+* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
+
+* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options:
+
+
+tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)})
+# =>
+
+
+Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
+
+* The old template handler API is deprecated and the new API simply requires a template handler to respond to call.
+
+* rhtml and rxml are finally removed as template handlers.
+
+* Moved etag responsibility from ActionDispatch::Response to the middleware stack.
+
+* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy.
+
+* file_field automatically adds :multipart => true to the enclosing form.
+
+* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility.
+
+* Added Rack::Cache to the default stack.
+
h4. Abstract Controller
h4. Action Controller
--
cgit v1.2.3
From 0e715d0b8ca83fd3053b8a8fa0a5cafbb0cccc79 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 31 Jul 2011 16:56:40 +0530
Subject: Rack::Sendfile is no more default middleware.
---
railties/guides/source/command_line.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index b34506d4d8..627e22f2de 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -386,7 +386,7 @@ Action Pack version 3.1.0
Active Resource version 3.1.0
Action Mailer version 3.1.0
Active Support version 3.1.0
-Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
+Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
Application root /home/foobar/commandsapp
Environment development
--
cgit v1.2.3
From 8015acf0324f83477e18437a192bcafa11101c93 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 31 Jul 2011 21:58:59 +0530
Subject: Adding more info as rake about is fixed
---
railties/guides/source/command_line.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index 627e22f2de..f48fa96451 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -389,6 +389,8 @@ Active Support version 3.1.0
Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
Application root /home/foobar/commandsapp
Environment development
+Database adapter sqlite3
+Database schema version 0
h4. +assets+
--
cgit v1.2.3
From 8f6959d5a4aa933b31fdb53f2687301dc5da0b47 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 31 Jul 2011 23:23:25 +0530
Subject: 3.1 release notes Active Record changes, Architectural changes and
organizing sections.
---
railties/guides/source/3_1_release_notes.textile | 189 ++++++++++++++++++++---
1 file changed, 165 insertions(+), 24 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index f520e4dfea..7d85d7a600 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -55,15 +55,23 @@ h3. Rails Architectural Changes
h4. Assets Pipeline
-TODO. point to assets guide, talk about rake assets:* tasks
+The major change in Rails 3.1 is the Assets Pipeline. It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines.
-h3. Documentation
+The assets pipeline is powered by "Sprockets":https://github.com/sstephenson/sprockets and is covered in the "Asset Pipeline":asset_pipeline.html guide.
-The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
+h4. HTTP Streaming
-More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects.
+HTTP Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it.
-h3. Internationalization
+h4. Default JS library is now jQuery
+
+jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch.
+
+h4. Identity Map
+
+Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion.
+
+Rails 3.1 comes with the identity map turned off by default.
h3. Railties
@@ -95,13 +103,9 @@ h3. Railties
h3. Action Pack
-TODO split items into controller/view sections.
-
-* A warning is given out if the CSRF token authenticity cannot be verified.
-
-* Allows AM/PM format in datetime selectors.
+h4. Abstract Controller
-* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
+h4. Action Controller
* Added streaming support, you can enable it with:
@@ -111,13 +115,25 @@ class PostsController < ActionController::Base
end
-Please read the docs at ActionController::Streaming for more information. TODO add links to api docs.
+Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
+
+* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+
+h4. Action Dispatch
* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers.
+h4. Action View
+
* Created ActionView::Renderer and specified an API for ActionView::Context.
-* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+TODO
+
+* A warning is given out if the CSRF token authenticity cannot be verified.
+
+* Allows AM/PM format in datetime selectors.
+
+* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call.
@@ -209,19 +225,148 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
* Added Rack::Cache to the default stack.
-h4. Abstract Controller
+h3. Active Record
-h4. Action Controller
+* Added a class method pluralize_table_names to singularize/pluralize table names of individual models. Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names.
+
+class User < ActiveRecord::Base
+ self.pluralize_table_names = false
+end
+
-h4. Action Dispatch
+* Added block setting of attributes to singular associations. The block will get called after the instance is initialized.
-h4. Action View
+
+class User < ActiveRecord::Base
+ has_one :account
+end
-h3. Active Record
+user.build_account{ |a| a.credit_limit => 100.0 }
+
-h3. Active Model
+* Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist.
+
+* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0
+
+* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities:
+
+
+class Post < ActiveRecord::Base
+ attr_accessible :title
+ attr_accessible :title, :published_at, :as => :admin
+end
+
+Post.new(params[:post], :as => :admin)
+
+
+* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation:
+
+* Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped.
+
+* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
+
+* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed.
+
+* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records.
+
+* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations.
+
+* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config.
-The major changes in Active Model are:
+* limits and offsets are removed from COUNT queries unless both are supplied.
+
+People.limit(1).count # => 'SELECT COUNT(*) FROM people'
+People.offset(1).count # => 'SELECT COUNT(*) FROM people'
+People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
+
+
+* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings.
+
+* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead.
+
+* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
+
+* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'.
+
+* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table.
+
+* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table.
+
+* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy)
+
+* Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement.
+
+
+change_table(:users, :bulk => true) do |t|
+ t.string :company_name
+ t.change :birthdate, :datetime
+end
+
+
+* Removed support for accessing attributes on a +has_and_belongs_to_many+ join table. has_many :through needs to be used.
+
+* Added a +create_association!+ method for +has_one+ and +belongs_to+ associations.
+
+* Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations. To use reversible migrations, just define the +change+ method.
+
+class MyMigration < ActiveRecord::Migration
+ def change
+ create_table(:horses) do
+ t.column :content, :text
+ t.column :remind_at, :datetime
+ end
+ end
+end
+
+
+* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down.
+
+* Migrations now use instance methods rather than class methods:
+
+class FooMigration < ActiveRecord::Migration
+ def up # Not self.up
+ ...
+ end
+end
+
+
+* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods.
+
+* Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used.
+
+
+has_many :things, :conditions => 'foo = #{bar}' # before
+has_many :things, :conditions => proc { "foo = #{bar}" } # after
+
+
+Inside the proc, 'self' is the object which is the owner of the association, unless you are eager loading the association, in which case 'self' is the class which the association is within.
+
+You can have any "normal" conditions inside the proc, so the following will work too:
+
+has_many :things, :conditions => proc { ["foo = ?", bar] }
+
+
+* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc.
+
+* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting.
+
+# Schema: User(name:string, password_digest:string, password_salt:string)
+class User < ActiveRecord::Base
+ has_secure_password
+end
+
+
+* When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns.
+
+* Setting the id of a belongs_to object will update the reference to the object.
+
+* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics.
+
+* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called.
+
+* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable.
+
+h3. Active Model
* +attr_accessible+ accepts an option +:as+ to specify a role.
@@ -233,8 +378,6 @@ The major changes in Active Model are:
h3. Active Resource
-The changes in Active Resource are:
-
* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example,
@@ -245,8 +388,6 @@ end
h3. Active Support
-The main changes in Active Support are:
-
* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant.
* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR.
--
cgit v1.2.3
From 61899bff17e161dbd706bfb900ac212fe90c3acd Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 20:37:42 +0530
Subject: Active Resource - guide for reading and writing data
---
railties/guides/source/active_resource_basics.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 64f0949475..8a36622814 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -24,10 +24,21 @@ end
Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes
life cycle methods that operate against a persistent store.
+h3. Reading and Writing Data
+
+Active Resource make request over HTTP using a standard JSON format. It mirrors the RESTful routing built into Action Controller but will also work with any other REST service that properly implements the protocol.
+
+h4. Read
+
+Read requests use the GET method and expect the JSON form of whatever resource/resources is/are being requested.
+
# Find a person with id = 1
ryan = Person.find(1)
+# Check if a person exists with id = 1
Person.exists?(1) # => true
+# Get all resources of Person class
+Person.all
h3. Changelog
--
cgit v1.2.3
From aa9da1fe70a109f86922b4ee83039f1cae1e6584 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 20:48:45 +0530
Subject: Active Resource - guide for create
---
railties/guides/source/active_resource_basics.textile | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 8a36622814..e40ca4fc42 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -34,13 +34,22 @@ Read requests use the GET method and expect the JSON form of whatever resource/r
# Find a person with id = 1
-ryan = Person.find(1)
+person = Person.find(1)
# Check if a person exists with id = 1
Person.exists?(1) # => true
# Get all resources of Person class
Person.all
+h4. Create
+
+Creating a new resource submits the JSON form of the resource as the body of the request with HTTP POST method and parse the response into Active Resource object.
+
+
+person = Person.create(:name => 'Vishnu')
+person.id # => 1
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 212654be02e28ee97d75819b0f799ccb6f7b9130 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 20:57:57 +0530
Subject: Active Resource - guide for update/save
---
railties/guides/source/active_resource_basics.textile | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index e40ca4fc42..1115b9848f 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -50,6 +50,16 @@ person = Person.create(:name => 'Vishnu')
person.id # => 1
+h4. Update
+
+To update an existing resource, 'save' method is used. This method make a HTTP PUT request in JSON format.
+
+
+person = Person.find(1)
+person.name = 'Atrai'
+person.save
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 1ea8d9c38d280e6f55ac3ad1ad4d27d48dcddc15 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Mon, 1 Aug 2011 21:02:48 +0530
Subject: Active Resource - guide for destroy
---
railties/guides/source/active_resource_basics.textile | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 1115b9848f..332d113fa7 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -60,6 +60,15 @@ person.name = 'Atrai'
person.save
+h4. Delete
+
+'destroy' method makes a HTTP DELETE request for an existing resource in JSON format to delete that resource.
+
+
+person = Person.find(1)
+person.destroy
+
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From ff0b1a3cc65ca8b2af02e62f940aaeffad606b16 Mon Sep 17 00:00:00 2001
From: pbflinn
Date: Mon, 1 Aug 2011 12:53:43 -0300
Subject: Fix typo 'console' -> 'constant'
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 477ee5a3a2..9b92edd250 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -71,7 +71,7 @@ module Rails
end
-The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ console, we'll see that when we get to the +in_rails_application?+ method.
+The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method.
Back in +rails/cli+, the next line is this:
--
cgit v1.2.3
From 5adb90a14f3fc3441a53476dd75217d1ecb8de97 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 3 Aug 2011 19:11:22 +0530
Subject: fixed incorrect tags
---
railties/guides/source/migrations.textile | 32 +++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index e51ee0f535..7b501807d6 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -477,7 +477,7 @@ Several methods are provided that allow you to control all this:
For example, this migration
-
+
class CreateProducts < ActiveRecord::Migration
def change
suppress_messages do
@@ -496,7 +496,7 @@ class CreateProducts < ActiveRecord::Migration
end
end
end
-
+
generates the following output
@@ -525,7 +525,7 @@ Bob goes on vacation.
Alice creates a migration for the +products+ table which adds a new column and initializes it.
She also adds a validation to the Product model for the new column.
-
+
# db/migrate/20100513121110_add_flag_to_product.rb
class AddFlagToProduct < ActiveRecord::Migration
@@ -534,19 +534,19 @@ class AddFlagToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes!(:flag => 'false') }
end
end
-
+
-
+
# app/model/product.rb
class Product < ActiveRecord::Base
validates_presence_of :flag
end
-
+
Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column.
-
+
# db/migrate/20100515121110_add_fuzz_to_product.rb
class AddFuzzToProduct < ActiveRecord::Migration
@@ -555,16 +555,16 @@ class AddFuzzToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
end
end
-
+
-
+
# app/model/product.rb
class Product < ActiveRecord::Base
validates_presence_of :flag
validates_presence_of :fuzz
end
-
+
Both migrations work for Alice.
@@ -575,12 +575,12 @@ Bob comes back from vacation and:
The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs.
-
+
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `fuzz' for #
-
+
A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion.
@@ -588,7 +588,7 @@ When using a faux model, it's a good idea to call +Product.reset_column_informat
If Alice had done this instead, there would have been no problem:
-
+
# db/migrate/20100513121110_add_flag_to_product.rb
class AddFlagToProduct < ActiveRecord::Migration
@@ -600,9 +600,9 @@ class AddFlagToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes!(:flag => false) }
end
end
-
+
-
+
# db/migrate/20100515121110_add_fuzz_to_product.rb
class AddFuzzToProduct < ActiveRecord::Migration
@@ -614,7 +614,7 @@ class AddFuzzToProduct < ActiveRecord::Migration
Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
end
end
-
+
h3. Schema Dumping and You
--
cgit v1.2.3
From 688b0c318f411a65bb2e27614dd9fe004427a344 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 3 Aug 2011 19:13:12 +0530
Subject: minor changes in migrations guide
---
railties/guides/source/migrations.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 7b501807d6..4476e067a6 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -540,7 +540,7 @@ end
# app/model/product.rb
class Product < ActiveRecord::Base
- validates_presence_of :flag
+ validates :flag, :presence => true
end
@@ -561,8 +561,7 @@ end
# app/model/product.rb
class Product < ActiveRecord::Base
- validates_presence_of :flag
- validates_presence_of :fuzz
+ validates :flag, :fuzz, :presence => true
end
@@ -594,9 +593,10 @@ If Alice had done this instead, there would have been no problem:
class AddFlagToProduct < ActiveRecord::Migration
class Product < ActiveRecord::Base
end
+
def change
add_column :products, :flag, :int
- Product.reset_column_information
+ Product.reset_column_information
Product.all.each { |f| f.update_attributes!(:flag => false) }
end
end
--
cgit v1.2.3
From e4d8a95443bbb86cb9a446397469229e85f21867 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 3 Aug 2011 19:34:23 +0530
Subject: typo fix
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 9b92edd250..6ab2706d6b 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -33,7 +33,7 @@ end
This file will attempt to load +rails/cli+ and if it cannot find it then add the +railties/lib+ path to the load path (+$:+) and will then try to require it again.
-h4. +railites/lib/rails/cli.rb+
+h4. +railties/lib/rails/cli.rb+
This file looks like this:
--
cgit v1.2.3
From fbd3e38d76e68ea49b5360a174e1a48f3079101e Mon Sep 17 00:00:00 2001
From: JudeArasu
Date: Wed, 3 Aug 2011 23:00:24 +0530
Subject: grammatical changes
---
railties/guides/source/form_helpers.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index bf2a7369a7..fa0ca5827a 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex
h4. A Generic Search Form
-One of the most basic forms you see on the web is a search form. This form contains:
+One of the most basic forms you will see on the web is a search form. This form contains:
# a form element with "GET" method,
# a label for the input,
@@ -807,3 +807,4 @@ h3. Authors
* Mislav Marohnić
* "Frederick Cheung":credits.html#fcheung
+
--
cgit v1.2.3
From 19122e767ca199f6b2b3e8f21d2634eb2f17a8b4 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Thu, 4 Aug 2011 15:02:13 -0700
Subject: Revert "grammatical changes"
Reason: As discussed in GitHub, it is debatable, and present tense
is fine (and simple, and preferred).
This reverts commit 54ccda9f0a5e4a5e72a4c159dc8787faaf65e8a2.
---
railties/guides/source/form_helpers.textile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index fa0ca5827a..bf2a7369a7 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex
h4. A Generic Search Form
-One of the most basic forms you will see on the web is a search form. This form contains:
+One of the most basic forms you see on the web is a search form. This form contains:
# a form element with "GET" method,
# a label for the input,
@@ -807,4 +807,3 @@ h3. Authors
* Mislav Marohnić
* "Frederick Cheung":credits.html#fcheung
-
--
cgit v1.2.3
From 6d4f91621871a23576ec6f343f08fd68dda95e0c Mon Sep 17 00:00:00 2001
From: Erik Michaels-Ober
Date: Mon, 25 Jul 2011 14:13:26 -0700
Subject: Add documentation for :format => true
---
railties/guides/source/routing.textile | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index 68fb22f5d8..99dd9a1cd2 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -569,6 +569,12 @@ NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +
match '*pages' => 'pages#show', :format => false
+NOTE: If you want to make the format segment mandatory, so it cannot be omitted, you can supply +:format => true+ like this:
+
+
+match '*pages' => 'pages#show', :format => true
+
+
h4. Redirection
You can redirect any path to another path using the +redirect+ helper in your router:
--
cgit v1.2.3
From ac287b2aa04c8376bf7d1f95c99047796442406e Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Fri, 5 Aug 2011 12:16:53 +0530
Subject: Adding Basic file for ActiveModel. @vatrai and @sukeerthiadiga is
going to take care other detailed stuff.
---
railties/guides/source/active_model_basics.textile | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 railties/guides/source/active_model_basics.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
new file mode 100644
index 0000000000..5e41d39447
--- /dev/null
+++ b/railties/guides/source/active_model_basics.textile
@@ -0,0 +1,16 @@
+h2. Active Model Basics
+
+This guide should provide you with all you need to get started using model classes. Active Model allow for Action Pack helpers to interact with non-ActiveRecord models. Active Model also helps building custom ORMs for use outside of the Rails framework.
+
+endprologue.
+
+WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.
+
+h3. Introduction
+
+Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes.
+
+
+h3. Changelog
+
+* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw
\ No newline at end of file
--
cgit v1.2.3
From 4bde1b0041d73accf75525697461ac6b9fad5404 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Fri, 5 Aug 2011 13:13:22 +0530
Subject: ActiveModel::AttributeMethods basic guide
---
railties/guides/source/active_model_basics.textile | 27 +++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 5e41d39447..c76469f62c 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -8,8 +8,33 @@ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not
h3. Introduction
-Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes.
+Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. Some of modules are explained below -
+h4. AttributeMethods
+
+AttributeMethods module can add custom prefixes and suffixes on methods of a class. It is used by defining the prefixes and suffixes, which methods on the object will use them.
+
+
+class Person
+ include ActiveModel::AttributeMethods
+
+ attribute_method_prefix 'reset_'
+ attribute_method_suffix '_highest?'
+ define_attribute_methods ['age']
+
+ attr_accessor :age
+
+private
+ def reset_attribute(attribute)
+ send("#{attribute}=", 0)
+ end
+
+ def attribute_highest?(attribute)
+ attribute > 100 ? true : false
+ end
+
+end
+
h3. Changelog
--
cgit v1.2.3
From 7963099b904031fef7d593d5be7e2061d1bcbfe8 Mon Sep 17 00:00:00 2001
From: Sukeerthi Adiga G
Date: Fri, 5 Aug 2011 13:13:31 +0530
Subject: ActiveResource::Validations module basics updated
---
.../guides/source/active_resource_basics.textile | 50 ++++++++++++++++++++++
1 file changed, 50 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile
index 332d113fa7..3294227f7b 100644
--- a/railties/guides/source/active_resource_basics.textile
+++ b/railties/guides/source/active_resource_basics.textile
@@ -69,6 +69,56 @@ person = Person.find(1)
person.destroy
+h3. Validations
+
+Module to support validation and errors with Active Resource objects. The module overrides Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned in the web service response. The module also adds an errors collection that mimics the interface of the errors provided by ActiveRecord::Errors.
+
+h4. Validating client side resources by overriding validation methods in base class
+
+
+class Person < ActiveResource::Base
+ self.site = "http://api.people.com:3000/"
+
+ protected
+
+ def validate
+ errors.add("last", "has invalid characters") unless last =~ /[a-zA-Z]*/
+ end
+end
+
+
+h4. Validating client side resources
+
+Consider a Person resource on the server requiring both a first_name and a last_name with a validates_presence_of :first_name, :last_name declaration in the model:
+
+
+person = Person.new(:first_name => "Jim", :last_name => "")
+person.save # => false (server returns an HTTP 422 status code and errors)
+person.valid? # => false
+person.errors.empty? # => false
+person.errors.count # => 1
+person.errors.full_messages # => ["Last name can't be empty"]
+person.errors[:last_name] # => ["can't be empty"]
+person.last_name = "Halpert"
+person.save # => true (and person is now saved to the remote service)
+
+
+h4. Public instance methods
+
+ActiveResource::Validations have three public instance methods
+
+h5. errors()
+
+This will return errors object that holds all information about attribute error messages
+
+h5. save_with_validation(options=nil)
+
+This validates the resource with any local validations written in base class and then it will try to POST if there are no errors.
+
+h5. valid?
+
+Runs all the local validations and will return true if no errors.
+
h3. Changelog
* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai
\ No newline at end of file
--
cgit v1.2.3
From 9eb3e637fb7ffa7a35847b5dd577c3a2736e5101 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Fri, 5 Aug 2011 13:34:28 +0530
Subject: AttributeMethods refector suffix method added some usages
---
railties/guides/source/active_model_basics.textile | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index c76469f62c..87a9658a94 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -30,12 +30,23 @@ private
end
def attribute_highest?(attribute)
- attribute > 100 ? true : false
+ send(attribute) > 100 ? true : false
end
end
+
+person = Person.new
+person.age = 110
+person.age_highest? # true
+person.reset_age # 0
+person.age_highest? # false
+
+h4. Callbacks
+
+
+
h3. Changelog
* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw
\ No newline at end of file
--
cgit v1.2.3
From b905f8c96326c86caafc20bec7e3722cf4813d2c Mon Sep 17 00:00:00 2001
From: Sukeerthi Adiga
Date: Fri, 5 Aug 2011 14:04:43 +0530
Subject: Rubygems => RubyGems
---
railties/guides/source/performance_testing.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index dbe6f97f5c..75f81cf13d 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -438,9 +438,9 @@ alias gcrails='~/rubygc/bin/rails'
Don't forget to use your aliases from now on.
-h6. Install Rubygems (1.8 only!)
+h6. Install RubyGems (1.8 only!)
-Download "Rubygems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above.
+Download "RubyGems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above.
h4. Using Ruby-Prof on MRI and REE
--
cgit v1.2.3
From bc49d6d1eb075900657b0f94d03c51d18a95a54d Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Fri, 5 Aug 2011 20:46:20 +1200
Subject: [asset pipeline] fixed example
Changed << to += because we are _concatenating_
this new array to the end of config array, NOT
pushing this array in it.
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 51cb332e38..13e28a25ba 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -297,7 +297,7 @@ The default matcher for compiling files will include +application.js+, +applicat
If you have other manifests or individual stylesheets and JavaScript files to include, you can append them to the +precompile+ array:
-config.assets.precompile << ['admin.js', 'admin.css', 'swfObject.js']
+config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them.
--
cgit v1.2.3
From 33d7a6bc55a983ea690961d3a434096fe80d0fca Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Fri, 5 Aug 2011 14:35:04 +0530
Subject: ActiveModel::Callbacks basic guide
---
railties/guides/source/active_model_basics.textile | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 87a9658a94..e4c84365d3 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -45,7 +45,31 @@ person.age_highest? # false
h4. Callbacks
+Callbacks gives Active Record style callbacks. This provides the ability to define the callbacks and those will run at appropriate time. After defining a callbacks you can wrap with before, after and around custom methods.
+
+class Person
+ extend ActiveModel::Callbacks
+
+ define_model_callbacks :update
+
+ before_update :reset_me
+
+ def update
+ _run_update_callbacks do
+ puts 'saving...'
+ end
+ end
+
+ def reset_me
+ puts 'before saving...'
+ end
+end
+
+person = Person.new
+person.update # before saving...
+ # saving...
+
h3. Changelog
--
cgit v1.2.3
From d5adaf2d38f81429e21d9670b6a852668edb3757 Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Fri, 5 Aug 2011 14:48:00 +0530
Subject: ActiveModel::Callbacks basic guide
---
railties/guides/source/active_model_basics.textile | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index e4c84365d3..92fa5bc8f4 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -57,18 +57,14 @@ class Person
def update
_run_update_callbacks do
- puts 'saving...'
+ # This will call when we are trying to call update on object.
end
end
def reset_me
- puts 'before saving...'
+ # This method will call when you are calling update on object as a before_update callback as defined.
end
end
-
-person = Person.new
-person.update # before saving...
- # saving...
h3. Changelog
--
cgit v1.2.3
From a3cf68291df3e9f5b23f56a90929c601ffc26ebd Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Fri, 5 Aug 2011 15:28:01 +0530
Subject: ActiveModel::Conversion basic guide
---
railties/guides/source/active_model_basics.textile | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 92fa5bc8f4..daf41d2296 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -67,6 +67,29 @@ class Person
end
+h4. Conversion
+
+If a class defines persisted? and id methods then you can include Conversion module in that class and you can able to call Rails conversion methods to objects of that class.
+
+
+class Person
+ include ActiveModel::Conversion
+
+ def persisted?
+ false
+ end
+
+ def id
+ nil
+ end
+end
+
+person = Person.new
+person.to_model == person #=> true
+person.to_key #=> nil
+person.to_param #=> nil
+
+
h3. Changelog
* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw
\ No newline at end of file
--
cgit v1.2.3
From 86ae14df4733cac1748513994caec2f9775ae224 Mon Sep 17 00:00:00 2001
From: Sukeerthi Adiga G
Date: Fri, 5 Aug 2011 15:21:12 +0530
Subject: Dirty object methods added to active model basics
---
railties/guides/source/active_model_basics.textile | 88 +++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index daf41d2296..404cc71c50 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -90,6 +90,92 @@ person.to_key #=> nil
person.to_param #=> nil
+h4. Dirty
+
+An object becomes dirty when an object is gone through one or more changes to its attributes and not yet saved. This gives the ability to check whether an object has been changed or not. It also has attribute based accessor methods. Lets consider a Person class with attributes first_name and last_name
+
+
+require 'rubygems'
+require 'active_model'
+
+class Person
+ include ActiveModel::Dirty
+ define_attribute_methods [:first_name, :last_name]
+
+ def first_name
+ @first_name
+ end
+
+ def first_name=(value)
+ first_name_will_change!
+ @first_name = value
+ end
+
+ def last_name
+ @last_name
+ end
+
+ def last_name=(value)
+ last_name_will_change!
+ @last_name = value
+ end
+
+ def save
+ @previously_changed = changes
+ end
+
+end
+
+
+h5. Querying object directly for its list of all changed attributes.
+
+
+person = Person.new
+person.first_name = "First Name"
+
+person.first_name #=> "First Name"
+person.first_name = "First Name Changed"
+
+person.changed? #=> true
+
+#returns an list of fields arry which all has been changed before saved.
+person.changed #=> ["first_name"]
+
+#returns a hash of the fields that have changed with their original values.
+person.changed_attributes #=> {"first_name" => "First Name Changed"}
+
+#returns a hash of changes, with the attribute names as the keys, and the values will be an array of the old and new value for that field.
+person.changes #=> {"first_name" => ["First Name","First Name Changed"]}
+
+
+h5. Attribute based accessor methods
+
+Track whether the particular attribute has been changed or not.
+
+
+#attr_name_changed?
+person.first_name #=> "First Name"
+
+#assign some other value to first_name attribute
+person.first_name = "First Name 1"
+
+person.first_name_changed? #=> true
+
+
+Track what was the previous value of the attribute.
+
+#attr_name_was accessor
+person.first_name_was #=> "First Name"
+
+
+
+Track both previous and current value of the changed attribute. Returns an array if changed else returns nil
+
+#attr_name_change
+person.first_name_change #=> ["First Name", "First Name 1"]
+person.last_name_change #=> nil
+
+
h3. Changelog
-* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw
\ No newline at end of file
+* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw
--
cgit v1.2.3
From bc9eaf422d9731bb4deb599f7b1e2e9014b870a0 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 6 Aug 2011 01:01:54 +0530
Subject: indentation fixes
---
railties/guides/source/initialization.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 6ab2706d6b..154df51cdc 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -348,10 +348,10 @@ The class *is* defined in +Rack::Server+, but is overwritten in +Rails::Server+
def parse!(args)
args, options = args.dup, {}
- opt_parser = OptionParser.new do |opts|
- opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
- opts.on("-p", "--port=port", Integer,
- "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
+ opt_parser = OptionParser.new do |opts|
+ opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
+ opts.on("-p", "--port=port", Integer,
+ "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
...
--
cgit v1.2.3
From 31b820eef92e218349a4a7f033868fc387a92e5b Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 6 Aug 2011 01:39:05 +0530
Subject: expand tmp:* tasks, and a few more additions in the command line
guide
---
railties/guides/source/command_line.textile | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index f48fa96451..6d5132a1bf 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -381,6 +381,7 @@ Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.3.6
Rack version 1.1
Rails version 3.1.0
+JavaScript Runtime Node.js (V8)
Active Record version 3.1.0
Action Pack version 3.1.0
Active Resource version 3.1.0
@@ -390,12 +391,12 @@ Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rai
Application root /home/foobar/commandsapp
Environment development
Database adapter sqlite3
-Database schema version 0
+Database schema version 20110805173523
h4. +assets+
-You can precompile the assets in app/assets using rake assets:precompile and remove compiled assets using rake assets:clean.
+You can precompile the assets in app/assets using rake assets:precompile and remove those compiled assets using rake assets:clean.
h4. +db+
@@ -460,13 +461,18 @@ h4. +test+
INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html
-Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should.
-
-The +test:+ namespace helps in running the different tests you will (hopefully!) write.
+Rails comes with a test suite called Test::Unit. Rails owes its stability to the use of tests. The tasks available in the +test:+ namespace helps in running the different tests you will hopefully write.
h4. +tmp+
-The Rails.root/tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry.
+The Rails.root/tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions.
+
+The +tmp:+ namespaced tasks will help you clear the Rails.root/tmp directory:
+
+* +rake tmp:cache:clear+ clears tmp/cache.
+* +rake tmp:sessions:clear+ clears tmp/sessions.
+* +rake tmp:sockets:clear+ clears tmp/sockets.
+* +rake tmp:clear+ clears all the three: cache, sessions and sockets.
h4. Miscellaneous
--
cgit v1.2.3
From 8320fbb3b01be05d133de445ecf0bbc172225dc5 Mon Sep 17 00:00:00 2001
From: JudeArasu
Date: Sat, 6 Aug 2011 05:21:27 +0530
Subject: prototype switch
---
railties/guides/source/3_1_release_notes.textile | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 7d85d7a600..b1eaca1ef9 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -67,6 +67,10 @@ h4. Default JS library is now jQuery
jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch.
+
+$ ruby /path/to/rails/bin/rails new myapp -j prototype --dev
+
+
h4. Identity Map
Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion.
@@ -417,3 +421,4 @@ h3. Credits
See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.
Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev.
+
--
cgit v1.2.3
From dbf22560c627c9b639d201887c137e822e4464be Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 6 Aug 2011 23:53:53 +0530
Subject: 3.1 release notes: organize action_pack notes
---
railties/guides/source/3_1_release_notes.textile | 86 ++++++++++++------------
1 file changed, 43 insertions(+), 43 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index b1eaca1ef9..eb4f775ff0 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -21,8 +21,6 @@ Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby ve
TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing.
-TODO. What else?
-
h3. Creating a Rails 3.1 application
@@ -68,7 +66,7 @@ h4. Default JS library is now jQuery
jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch.
-$ ruby /path/to/rails/bin/rails new myapp -j prototype --dev
+$ rails new myapp -j prototype
h4. Identity Map
@@ -103,41 +101,25 @@ h3. Railties
* Added Rack::Cache to the default middleware stack.
-* TODO Engine related changes
+* Engines received a major update - You can mount them at any path, enable assets, run generators etc.
h3. Action Pack
-h4. Abstract Controller
-
h4. Action Controller
-* Added streaming support, you can enable it with:
-
-
-class PostsController < ActionController::Base
- stream :only => :index
-end
-
-
-Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
-
-* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
-
-h4. Action Dispatch
-
-* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers.
+* A warning is given out if the CSRF token authenticity cannot be verified.
-h4. Action View
+* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used.
-* Created ActionView::Renderer and specified an API for ActionView::Context.
+* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log.
-TODO
+* URL parameters which return nil for +to_param+ are now removed from the query string.
-* A warning is given out if the CSRF token authenticity cannot be verified.
+* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
-* Allows AM/PM format in datetime selectors.
+* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
-* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
+* +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options.
* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call.
@@ -180,31 +162,43 @@ class PostsController < ApplicationController
end
-* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used.
+* Added streaming support, you can enable it with:
-* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete })
+
+class PostsController < ActionController::Base
+ stream :only => :index
+end
+
-* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
+Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
-* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log.
+* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused.
-* URL parameters which return nil for +to_param+ are now removed from the query string.
+h4. Action Dispatch
* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array.
-* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false.
+* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers.
-* Added HTML5 button_tag helper.
+* Added Rack::Cache to the default stack.
+
+* Moved etag responsibility from ActionDispatch::Response to the middleware stack.
+
+* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy.
* Template lookup now searches further up in the inheritance chain.
-* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version?
+h4. Action View
-* url_for and named url helpers now accept :subdomain and :domain as options.
+* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false.
-* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused.
+* Created ActionView::Renderer and specified an API for ActionView::Context.
-* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
+* In place SafeBuffer mutation is prohibited in Rails 3.1.
+
+* Added HTML5 button_tag helper.
+
+* +file_field+ automatically adds :multipart => true to the enclosing form.
* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options:
@@ -215,19 +209,23 @@ tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)})
Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
+* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility.
+
* The old template handler API is deprecated and the new API simply requires a template handler to respond to call.
* rhtml and rxml are finally removed as template handlers.
-* Moved etag responsibility from ActionDispatch::Response to the middleware stack.
+* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not.
-* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy.
+* The submit form helper does not generate an id "object_name_id" anymore.
-* file_field automatically adds :multipart => true to the enclosing form.
+* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete })
-* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility.
+* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
-* Added Rack::Cache to the default stack.
+* Allows AM/PM format in datetime selectors.
+
+* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
h3. Active Record
@@ -380,6 +378,8 @@ h3. Active Model
* ActiveModel::AttributeMethods allows attributes to be defined on demand.
+* Added support for selectively enabling and disabling observers.
+
h3. Active Resource
* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example,
--
cgit v1.2.3
From b840d71bfb702b121b48832f984090e202793f10 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Sun, 7 Aug 2011 09:37:39 +1200
Subject: [asset pipeline] Update Capistrano info
v2.8.0 of Capistrano has a recipe to handle precompile
and symlinking.
---
railties/guides/source/asset_pipeline.textile | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 13e28a25ba..3a87c90516 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -276,17 +276,15 @@ The rake task is:
rake assets:precompile
-You can run this as part of a Capistrano deployment:
+Capistrano (v2.8.0+) has a recipe to to handle this in deployment. Add the following line to +Capfile+:
-before 'deploy:symlink' do
- run "cd #{release_path}; RAILS_ENV=#{rails_env} rake assets:precompile"
-end
+load 'deploy/assets'
-If you are not precompiling your assets, and you are using the default cache file store (which is the file system), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure in order to persist the cached file between deployments.
+This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this folder you'll need to write your own deployment task.
-TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). Note: Capistrano folks are working on a recipe - update this when it available (see https://github.com/capistrano/capistrano/pull/35).
+It is important for this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page.
The default matcher for compiling files will include +application.js+, +application.css+ and all files that do not end in +js+ or +css+:
--
cgit v1.2.3
From 8c133fc4c0c04ddfe6f964062c4dcfc65ceb0222 Mon Sep 17 00:00:00 2001
From: ov3y
Date: Sun, 7 Aug 2011 07:55:59 -0300
Subject: Point to current, official upgrade plugin
---
railties/guides/source/3_0_release_notes.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index fbb684978a..d22c76dd81 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -59,12 +59,12 @@ The +config.gem+ method is gone and has been replaced by using +bundler+ and a +
h4. Upgrade Process
-To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/jm/rails_upgrade has been created to automate part of it.
+To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/rails/rails_upgrade has been created to automate part of it.
Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following:
-$ ruby script/plugin install git://github.com/jm/rails_upgrade.git
+$ ruby script/plugin install git://github.com/rails/rails_upgrade.git
You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin
--
cgit v1.2.3
From 93ec7bb59a62702051377e9beb43501ccd9d0f2a Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 7 Aug 2011 21:45:12 +0530
Subject: 3.1 release notes: fixed font changes
---
railties/guides/source/3_1_release_notes.textile | 43 ++++++++++++------------
1 file changed, 21 insertions(+), 22 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index eb4f775ff0..5f09d8fd2b 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -121,7 +121,7 @@ h4. Action Controller
* +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options.
-* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call.
+* Added +Base.http_basic_authenticate_with+ to do simple http basic authentication with a single class method call.
class PostsController < ApplicationController
@@ -190,13 +190,13 @@ h4. Action Dispatch
h4. Action View
-* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false.
+* Added an +:authenticity_token+ option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false.
* Created ActionView::Renderer and specified an API for ActionView::Context.
-* In place SafeBuffer mutation is prohibited in Rails 3.1.
+* In place +SafeBuffer+ mutation is prohibited in Rails 3.1.
-* Added HTML5 button_tag helper.
+* Added HTML5 +button_tag+ helper.
* +file_field+ automatically adds :multipart => true to the enclosing form.
@@ -248,9 +248,9 @@ user.build_account{ |a| a.credit_limit => 100.0 }
* Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist.
-* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0
+* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0.
-* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities:
+* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities:
class Post < ActiveRecord::Base
@@ -261,19 +261,19 @@ end
Post.new(params[:post], :as => :admin)
-* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation:
+* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation:
* Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped.
* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
-* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed.
+* +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed.
-* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records.
+* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
-* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations.
+* Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations.
-* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config.
+* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config.
* limits and offsets are removed from COUNT queries unless both are supplied.
@@ -286,9 +286,9 @@ People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET
* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead.
-* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
+* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
-* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'.
+* The behavior of association.destroy for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'.
* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table.
@@ -332,7 +332,7 @@ class FooMigration < ActiveRecord::Migration
end
-* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods.
+* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's +change+ method instead of the ordinary +up+ and +down+ methods.
* Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used.
@@ -348,7 +348,7 @@ You can have any "normal" conditions inside the proc, so the following will work
has_many :things, :conditions => proc { ["foo = ?", bar] }
-* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc.
+* Previously +:insert_sql+ and +:delete_sql+ on +has_and_belongs_to_many+ association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc.
* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting.
@@ -360,13 +360,13 @@ end
* When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns.
-* Setting the id of a belongs_to object will update the reference to the object.
+* Setting the id of a +belongs_to+ object will update the reference to the object.
-* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics.
+* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics.
-* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called.
+* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called.
-* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable.
+* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable.
h3. Active Model
@@ -394,13 +394,13 @@ h3. Active Support
* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant.
-* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR.
+* Added a new reporting method Kernel#quietly which silences both +STDOUT+ and +STDERR+.
* Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object.
* Added Object#in? to test if an object is included in another object.
-* LocalCache strategy is now a real middleware class and no longer an anonymous class.
+* +LocalCache+ strategy is now a real middleware class and no longer an anonymous class.
* ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes.
@@ -421,4 +421,3 @@ h3. Credits
See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.
Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev.
-
--
cgit v1.2.3
From 32da2f864eb9e1f626f25e5d46a38d0c0d214d15 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Mon, 8 Aug 2011 18:02:19 +1200
Subject: [asset pipeline] update to reflect new sendfile header default
X-Sendfile headers are now set to nil and are off by default.
See commit eff7fddeb26eaa346827
---
railties/guides/source/asset_pipeline.textile | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 3a87c90516..3eede31572 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -385,16 +385,14 @@ This is a handy option if you have any existing project (pre Rails 3.1) that alr
h4. X-Sendfile Headers
-The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the web server to do the file serving, which is usually faster. Both Apache and nginx support this option.
+The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. This option is off be default, but can be enabled if your server supports it. When enabled, this passes responsibility for serving the file to the web server, which is faster.
-The configuration is available in config/environments/production.rb.
+Apache and nginx support this option which is enabled in config/environments/production.rb.
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
-You should check that your server or hosting service actually supports this, otherwise comment it out.
-
WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behavior.
h3. How Caching Works
--
cgit v1.2.3
From 49e81f21a3e6facac06c49739644dbb36c94f794 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Mon, 8 Aug 2011 22:21:25 +1200
Subject: [asset pipeline] update snippet to reflect patch
Two commented lines in example to match the
commit (8845ae683e2688)
---
railties/guides/source/asset_pipeline.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 3eede31572..8a4d61dc3a 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -390,7 +390,8 @@ The X-Sendfile header is a directive to the server to ignore the response from t
Apache and nginx support this option which is enabled in config/environments/production.rb.
-config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
+# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behavior.
--
cgit v1.2.3
From 9cf56c709b6ec2ab0479f664761596f6c64f8887 Mon Sep 17 00:00:00 2001
From: Floris Huetink
Date: Tue, 9 Aug 2011 15:48:34 +0200
Subject: Fixed typo (attachments method name was missing an s) in Action
Mailer basics guide
---
railties/guides/source/action_mailer_basics.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index f05d9dcf1c..5b2212d9cb 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -404,7 +404,7 @@ Will put the HTML part first, and the plain text part second.
h4. Sending Emails with Attachments
-Attachments can be added by using the +attachment+ method:
+Attachments can be added by using the +attachments+ method:
class UserMailer < ActionMailer::Base
--
cgit v1.2.3
From 3b4e7c9f8e38bdc7517e85c413f48f5aadf17eec Mon Sep 17 00:00:00 2001
From: "Mr. Wolfe"
Date: Wed, 10 Aug 2011 23:22:16 +0200
Subject: update rails on rack guide, section 2 needs to be changed or maybe
deleted
---
railties/guides/source/rails_on_rack.textile | 33 ++++++++++++++++++----------
1 file changed, 21 insertions(+), 12 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index 8d5985dba8..ea26334ba0 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -89,23 +89,32 @@ $ rake middleware
For a freshly generated Rails application, this might produce something like:
+use ActionDispatch::Static
use Rack::Lock
-use ActionController::Failsafe
-use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"}
-use Rails::Rack::Metal
-use ActionDispatch::RewindableInput
-use ActionController::ParamsParser
-use Rack::MethodOverride
-use Rack::Head
+use ActiveSupport::Cache::Strategy::LocalCache
+use Rack::Runtime
+use Rails::Rack::Logger
+use ActionDispatch::ShowExceptions
+use ActionDispatch::RemoteIp
+use Rack::Sendfile
+use ActionDispatch::Callbacks
+use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
-run ActionController::Dispatcher.new
+use ActionDispatch::Cookies
+use ActionDispatch::Session::CookieStore
+use ActionDispatch::Flash
+use ActionDispatch::ParamsParser
+use Rack::MethodOverride
+use ActionDispatch::Head
+use ActionDispatch::BestStandardsSupport
+run Blog::Application.routes
Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section.
h4. Configuring Middleware Stack
-Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb.
+Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb.
h5. Adding a Middleware
@@ -118,7 +127,7 @@ You can add a new middleware to the middleware stack using any of the following
* config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack.
-# config/environment.rb
+# config/application.rb
# Push Rack::BounceFavicon at the bottom
config.middleware.use Rack::BounceFavicon
@@ -133,7 +142,7 @@ h5. Swapping a Middleware
You can swap an existing middleware in the middleware stack using +config.middleware.swap+.
-# config/environment.rb
+# config/application.rb
# Replace ActionController::Failsafe with Lifo::Failsafe
config.middleware.swap ActionController::Failsafe, Lifo::Failsafe
@@ -198,7 +207,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp
Clear the existing Rails middleware stack
-# environment.rb
+# application.rb
config.middleware.clear
--
cgit v1.2.3
From 635c1ca007a4e86f277508ec5b116ebcbe71a7f2 Mon Sep 17 00:00:00 2001
From: "Mr. Wolfe"
Date: Wed, 10 Aug 2011 23:27:00 +0200
Subject: Revert "update rails on rack guide, section 2 needs to be changed or
maybe deleted"
This reverts commit 7a4e545eccf834cb620df0f909ef3f4bec4e6608.
---
railties/guides/source/rails_on_rack.textile | 33 ++++++++++------------------
1 file changed, 12 insertions(+), 21 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index ea26334ba0..8d5985dba8 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -89,32 +89,23 @@ $ rake middleware
For a freshly generated Rails application, this might produce something like:
-use ActionDispatch::Static
use Rack::Lock
-use ActiveSupport::Cache::Strategy::LocalCache
-use Rack::Runtime
-use Rails::Rack::Logger
-use ActionDispatch::ShowExceptions
-use ActionDispatch::RemoteIp
-use Rack::Sendfile
-use ActionDispatch::Callbacks
-use ActiveRecord::ConnectionAdapters::ConnectionManagement
-use ActiveRecord::QueryCache
-use ActionDispatch::Cookies
-use ActionDispatch::Session::CookieStore
-use ActionDispatch::Flash
-use ActionDispatch::ParamsParser
+use ActionController::Failsafe
+use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"}
+use Rails::Rack::Metal
+use ActionDispatch::RewindableInput
+use ActionController::ParamsParser
use Rack::MethodOverride
-use ActionDispatch::Head
-use ActionDispatch::BestStandardsSupport
-run Blog::Application.routes
+use Rack::Head
+use ActiveRecord::QueryCache
+run ActionController::Dispatcher.new
Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section.
h4. Configuring Middleware Stack
-Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb.
+Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb.
h5. Adding a Middleware
@@ -127,7 +118,7 @@ You can add a new middleware to the middleware stack using any of the following
* config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack.
-# config/application.rb
+# config/environment.rb
# Push Rack::BounceFavicon at the bottom
config.middleware.use Rack::BounceFavicon
@@ -142,7 +133,7 @@ h5. Swapping a Middleware
You can swap an existing middleware in the middleware stack using +config.middleware.swap+.
-# config/application.rb
+# config/environment.rb
# Replace ActionController::Failsafe with Lifo::Failsafe
config.middleware.swap ActionController::Failsafe, Lifo::Failsafe
@@ -207,7 +198,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp
Clear the existing Rails middleware stack
-# application.rb
+# environment.rb
config.middleware.clear
--
cgit v1.2.3
From 1b0d03b5db04f19d9428959844624a47f6ba1a2f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emili=20Parre=C3=B1o?=
Date: Wed, 10 Aug 2011 23:32:11 +0200
Subject: update rails on rack guide, section 2 needs to be changed or maybe
deleted
---
railties/guides/source/rails_on_rack.textile | 33 ++++++++++++++++++----------
1 file changed, 21 insertions(+), 12 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index 8d5985dba8..818df0ffaf 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -89,23 +89,32 @@ $ rake middleware
For a freshly generated Rails application, this might produce something like:
+use ActionDispatch::Static
use Rack::Lock
-use ActionController::Failsafe
-use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"}
-use Rails::Rack::Metal
-use ActionDispatch::RewindableInput
-use ActionController::ParamsParser
-use Rack::MethodOverride
-use Rack::Head
+use ActiveSupport::Cache::Strategy::LocalCache
+use Rack::Runtime
+use Rails::Rack::Logger
+use ActionDispatch::ShowExceptions
+use ActionDispatch::RemoteIp
+use Rack::Sendfile
+use ActionDispatch::Callbacks
+use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
-run ActionController::Dispatcher.new
+use ActionDispatch::Cookies
+use ActionDispatch::Session::CookieStore
+use ActionDispatch::Flash
+use ActionDispatch::ParamsParser
+use Rack::MethodOverride
+use ActionDispatch::Head
+use ActionDispatch::BestStandardsSupport
+run Blog::Application.routes
Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section.
h4. Configuring Middleware Stack
-Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb.
+Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb.
h5. Adding a Middleware
@@ -118,7 +127,7 @@ You can add a new middleware to the middleware stack using any of the following
* config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack.
-# config/environment.rb
+# config/application.rb
# Push Rack::BounceFavicon at the bottom
config.middleware.use Rack::BounceFavicon
@@ -133,7 +142,7 @@ h5. Swapping a Middleware
You can swap an existing middleware in the middleware stack using +config.middleware.swap+.
-# config/environment.rb
+# config/application.rb
# Replace ActionController::Failsafe with Lifo::Failsafe
config.middleware.swap ActionController::Failsafe, Lifo::Failsafe
@@ -198,7 +207,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp
Clear the existing Rails middleware stack
-# environment.rb
+# config/application.rb
config.middleware.clear
--
cgit v1.2.3
From 54cd73e20d5fe2c4168e04f9525b8793e9e3c64c Mon Sep 17 00:00:00 2001
From: Vishnu Atrai
Date: Fri, 5 Aug 2011 20:15:48 +0530
Subject: ActiveModel::Validations basic guide
---
railties/guides/source/active_model_basics.textile | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 404cc71c50..f3a2b2edbc 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -176,6 +176,30 @@ person.first_name_change #=> ["First Name", "First Name 1"]
person.last_name_change #=> nil
+h4. Validations
+
+Validations module adds the ability to class objects to validate them in Active Record style.
+
+
+class Person
+ include ActiveModel::Validations
+
+ attr_accessor :name, :email
+
+ validates :name, :presence => true
+ validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i
+
+end
+
+person = Person.new
+person.valid? #=> false
+person.name = 'vishnu'
+person.email = 'me'
+person.valid? #=> false
+person.email = 'me@vishnuatrai.com'
+person.valid? #=> true
+
+
h3. Changelog
* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw
--
cgit v1.2.3
From 0196f0feb12d6a093f7ffa95de9f878be17adea7 Mon Sep 17 00:00:00 2001
From: Sebastian Martinez
Date: Thu, 11 Aug 2011 21:28:57 -0300
Subject: Some fixes on the 3_1_release_notes guide.
---
railties/guides/source/3_1_release_notes.textile | 44 ++++++++++++------------
1 file changed, 22 insertions(+), 22 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 5f09d8fd2b..c1585c707e 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -13,7 +13,7 @@ endprologue.
h3. Upgrading to Rails 3.1
-If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes:
+If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 in case you haven't and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes:
h4. Rails 3.1 requires at least Ruby 1.8.7
@@ -31,13 +31,13 @@ $ cd myapp
h4. Vendoring Gems
-Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
+Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.
More information: - "bundler homepage":http://gembundler.com
h4. Living on the Edge
-+Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag:
++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated +bundle+ command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag:
$ rails new myapp --edge
@@ -79,11 +79,11 @@ h3. Railties
* jQuery is the new default JavaScript library.
-* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems.
+* jQuery and Prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems.
* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline.
-* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified.
+* Generating an application or a plugin runs +bundle install+ unless --skip-gemfile or --skip-bundle is specified.
* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available.
@@ -115,7 +115,7 @@ h4. Action Controller
* URL parameters which return nil for +to_param+ are now removed from the query string.
-* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
@@ -184,7 +184,7 @@ h4. Action Dispatch
* Moved etag responsibility from ActionDispatch::Response to the middleware stack.
-* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy.
+* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy.
* Template lookup now searches further up in the inheritance chain.
@@ -209,7 +209,7 @@ tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)})
Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
-* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility.
+* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases +csrf_meta_tag+ for backwards compatibility.
* The old template handler API is deprecated and the new API simply requires a template handler to respond to call.
@@ -219,13 +219,13 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
* The submit form helper does not generate an id "object_name_id" anymore.
-* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete })
+* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }).
-* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
+* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
* Allows AM/PM format in datetime selectors.
-* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
+* +auto_link+ has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
h3. Active Record
@@ -261,7 +261,7 @@ end
Post.new(params[:post], :as => :admin)
-* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation:
+* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation.
* Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped.
@@ -282,19 +282,19 @@ People.offset(1).count # => 'SELECT COUNT(*) FROM people'
People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
-* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings.
+* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called +CollectionProxy+, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings.
* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead.
-* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
+* Support the :dependent option on has_many :through associations. For historical and practical reasons, +:delete_all+ is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is +:nullify+ for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
-* The behavior of association.destroy for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'.
+* The behavior of +association.destroy+ for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'.
-* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table.
+* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table.
-* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table.
+* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table.
-* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy)
+* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy).
* Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement.
@@ -321,7 +321,7 @@ class MyMigration < ActiveRecord::Migration
end
-* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down.
+* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define +up+ and +down+ in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down.
* Migrations now use instance methods rather than class methods:
@@ -392,7 +392,7 @@ end
h3. Active Support
-* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant.
+* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in +load_missing_constant+.
* Added a new reporting method Kernel#quietly which silences both +STDOUT+ and +STDERR+.
@@ -404,13 +404,13 @@ h3. Active Support
* ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes.
-* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache.
+* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new +ClassCache+.
* Backports Range#cover? as an alias for Range#include? in Ruby 1.8.
* Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time.
-* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants!
+* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants!.
Deprecations:
--
cgit v1.2.3
From 4d525b8c032b23a21a4c494755ce70b187e102ce Mon Sep 17 00:00:00 2001
From: Hendy Tanata
Date: Sun, 14 Aug 2011 13:05:25 +0800
Subject: Fix tt tag appearing on 3_1_release_notes guide.
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index c1585c707e..4da3aaaf7a 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -219,7 +219,7 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
* The submit form helper does not generate an id "object_name_id" anymore.
-* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }).
+* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(==@==post, remote: true, method: :delete) instead of form_for(==@==post, remote: true, html: { method: :delete }).
* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
--
cgit v1.2.3
From e10b288bc64b8b8160bf880ca2343469558803f9 Mon Sep 17 00:00:00 2001
From: Hendy Tanata
Date: Sun, 14 Aug 2011 12:30:37 +0800
Subject: Use fixed-width font where necessary.
---
railties/guides/source/3_1_release_notes.textile | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 4da3aaaf7a..4db6b2e8e0 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -81,13 +81,13 @@ h3. Railties
* jQuery and Prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems.
-* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline.
+* The application generator accepts an option +-j+ which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the +Gemfile+, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline.
-* Generating an application or a plugin runs +bundle install+ unless --skip-gemfile or --skip-bundle is specified.
+* Generating an application or a plugin runs +bundle install+ unless +--skip-gemfile+ or +--skip-bundle+ is specified.
-* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available.
+* The controller and resource generators will now automatically produce asset stubs (this can be turned off with +--skip-assets+). These stubs will use CoffeeScript and Sass, if those libraries are available.
-* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, --old-style-hash can be passed.
+* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, +--old-style-hash+ can be passed.
* Scaffold controller generator creates format block for JSON instead of XML.
@@ -109,15 +109,15 @@ h4. Action Controller
* A warning is given out if the CSRF token authenticity cannot be verified.
-* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used.
+* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, +:only+ or +:except+ can be used.
* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log.
-* URL parameters which return nil for +to_param+ are now removed from the query string.
+* URL parameters which return +nil+ for +to_param+ are now removed from the query string.
* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
-* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
+* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to +false+ will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
* +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options.
@@ -200,7 +200,7 @@ h4. Action View
* +file_field+ automatically adds :multipart => true to the enclosing form.
-* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options:
+* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a +:data+ hash of options:
tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)})
@@ -219,7 +219,7 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
* The submit form helper does not generate an id "object_name_id" anymore.
-* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(==@==post, remote: true, method: :delete) instead of form_for(==@==post, remote: true, html: { method: :delete }).
+* Allows FormHelper#form_for to specify the +:method+ as a direct option instead of through the +:html+ hash. form_for(==@==post, remote: true, method: :delete) instead of form_for(==@==post, remote: true, html: { method: :delete }).
* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper.
@@ -284,7 +284,7 @@ People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET
* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called +CollectionProxy+, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings.
-* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead.
+* Singular associations (+has_one+, +belongs_to+) no longer have a proxy and simply returns the associated record or +nil+. This means that you should not use undocumented methods such as +bob.mother.create+ - use +bob.create_mother+ instead.
* Support the :dependent option on has_many :through associations. For historical and practical reasons, +:delete_all+ is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is +:nullify+ for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
@@ -341,7 +341,7 @@ has_many :things, :conditions => 'foo = #{bar}' # before
has_many :things, :conditions => proc { "foo = #{bar}" } # after
-Inside the proc, 'self' is the object which is the owner of the association, unless you are eager loading the association, in which case 'self' is the class which the association is within.
+Inside the proc, +self+ is the object which is the owner of the association, unless you are eager loading the association, in which case +self+ is the class which the association is within.
You can have any "normal" conditions inside the proc, so the following will work too:
@@ -366,7 +366,7 @@ end
* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called.
-* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable.
+* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return +true+ for new_record?, have a +nil+ id field, and is saveable.
h3. Active Model
--
cgit v1.2.3
From 33be1b0e4bfe6b1dd2acf34d6f214f1b6c776bcc Mon Sep 17 00:00:00 2001
From: Hendy Tanata
Date: Sun, 14 Aug 2011 13:11:36 +0800
Subject: Active Model instead of ActiveModel.
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 4db6b2e8e0..77dff26280 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -250,7 +250,7 @@ user.build_account{ |a| a.credit_limit => 100.0 }
* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0.
-* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities:
+* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of Active Model's new mass assignment capabilities:
class Post < ActiveRecord::Base
--
cgit v1.2.3
From 9f76e47c9b897d3a2595129c61fe0e9737253347 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 14 Aug 2011 19:52:22 +0530
Subject: added a few more items in the release notes
---
railties/guides/source/3_1_release_notes.textile | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 77dff26280..ba36735a0b 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -166,16 +166,18 @@ end
class PostsController < ActionController::Base
- stream :only => :index
+ stream
end
-Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
+You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused.
h4. Action Dispatch
+* config.action_dispatch.x_sendfile_header now defaults to +nil+ and config/environments/production.rb doesn't set any particular value for it. This allows servers to set it through X-Sendfile-Type.
+
* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array.
* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers.
@@ -368,6 +370,8 @@ end
* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return +true+ for new_record?, have a +nil+ id field, and is saveable.
+* The query cache now works with prepared statements. No changes in the applications are required.
+
h3. Active Model
* +attr_accessible+ accepts an option +:as+ to specify a role.
@@ -380,6 +384,8 @@ h3. Active Model
* Added support for selectively enabling and disabling observers.
+* Alternate I18n namespace lookup is no longer supported.
+
h3. Active Resource
* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example,
--
cgit v1.2.3
From 3c5715575d85e0df69f84357769fc4696fdec3da Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 14 Aug 2011 20:15:22 +0530
Subject: document alias for rails runner
---
railties/guides/source/initialization.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 154df51cdc..49d7513448 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -190,7 +190,8 @@ aliases = {
"g" => "generate",
"c" => "console",
"s" => "server",
- "db" => "dbconsole"
+ "db" => "dbconsole",
+ "r" => "runner"
}
command = ARGV.shift
--
cgit v1.2.3
From ac4dc5e240242ed53885e4cac7b48dd93773a329 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 14 Aug 2011 20:15:51 +0530
Subject: rephrase how the verbose methods in a migration work
---
railties/guides/source/migrations.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 4476e067a6..9da12e2e18 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -471,8 +471,8 @@ By default migrations tell you exactly what they're doing and how long it took.
Several methods are provided that allow you to control all this:
-* +suppress_messages+ suppresses any output generated by its block
-* +say+ outputs text (the second argument controls whether it is indented or not)
+* +suppress_messages+ takes a block as an argument and suppresses any output generated by the block.
+* +say+ takes a message argument and outputs it as is. A second boolean argument can be passed to specify whether to indent or not.
* +say_with_time+ outputs text along with how long it took to run its block. If the block returns an integer it assumes it is the number of rows affected.
For example, this migration
@@ -510,7 +510,7 @@ generates the following output
20080906170109 CreateProducts: migrated (10.0097s)
-If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress any output.
+If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress all output.
h3. Using Models in Your Migrations
--
cgit v1.2.3
From 169a50930f330f94c189b5fcd665a3d209ccbcfa Mon Sep 17 00:00:00 2001
From: Raul Murciano
Date: Sun, 14 Aug 2011 10:13:23 -0700
Subject: Action Mailer guide update: the :to parameter now supports both
String and Array values to indicate recipients.
---
railties/guides/source/action_mailer_basics.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 5b2212d9cb..4bf9161425 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -242,11 +242,11 @@ end
h5. Sending Email To Multiple Recipients
-It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The to: key however expects a string so you have join the list of recipients using a comma.
+It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated with commas.
class AdminMailer < ActionMailer::Base
- default :to => Admin.all.map(&:email).join(", "),
+ default :to => Admin.all.map(&:email),
:from => "notification@example.com"
def new_registration(user)
--
cgit v1.2.3
From 51b2502c5e059bb31ecb5881ec1b19279a49cadf Mon Sep 17 00:00:00 2001
From: Raul Murciano
Date: Sun, 14 Aug 2011 10:14:28 -0700
Subject: Action Mailer guide: mention how to use :cc and :bcc parameters.
---
railties/guides/source/action_mailer_basics.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 4bf9161425..517a47d233 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -256,6 +256,8 @@ It is possible to send email to one or more recipients in one email (for e.g. in
end
+The same format can be used to set carbon copy (Cc:) and blind carbon copy (Bcc:) recipients, by using the :cc and :bcc keys respectively.
+
h5. Sending Email With Name
Sometimes you wish to show the name of the person instead of just their email address when they receive the email. The trick to doing that is
--
cgit v1.2.3
From 7712db4c82975403913e0395f860242ead322570 Mon Sep 17 00:00:00 2001
From: Raul Murciano
Date: Sun, 14 Aug 2011 10:24:48 -0700
Subject: Typo
---
railties/guides/source/action_mailer_basics.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 517a47d233..0941b06cfe 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -242,7 +242,7 @@ end
h5. Sending Email To Multiple Recipients
-It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated with commas.
+It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas.
class AdminMailer < ActionMailer::Base
--
cgit v1.2.3
From c026cc254cd1afd2f4f3dbaa6b537ed4c8c5a4f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kamil=20=C5=9Aliwak?=
Date: Mon, 15 Aug 2011 03:13:07 +0300
Subject: Fix a typo in 'Configuring Rails Applications' guide
- The initializer is called `set_autoload_paths`, not `set_autoload_path`. See https://github.com/rails/rails/blob/master/railties/lib/rails/engine.rb#L506
---
railties/guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 2ff5de2334..110c04f66e 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -557,7 +557,7 @@ The error occurred while evaluating nil.each
*+set_load_path+* This initializer runs before +bootstrap_hook+. Adds the +vendor+, +lib+, all directories of +app+ and any paths specified by +config.load_paths+ to +$LOAD_PATH+.
-*+set_autoload_path+* This initializer runs before +bootstrap_hook+. Adds all sub-directories of +app+ and paths specified by +config.autoload_paths+ to +ActiveSupport::Dependencies.autoload_paths+.
+*+set_autoload_paths+* This initializer runs before +bootstrap_hook+. Adds all sub-directories of +app+ and paths specified by +config.autoload_paths+ to +ActiveSupport::Dependencies.autoload_paths+.
*+add_routing_paths+* Loads (by default) all +config/routes.rb+ files (in the application and railties, including engines) and sets up the routes for the application.
--
cgit v1.2.3
From b8363f84da3356d66a7b30b8d180ad01eb7e0eb3 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Mon, 15 Aug 2011 20:36:32 +0530
Subject: minor changes in app templates guide
---
railties/guides/source/rails_application_templates.textile | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile
index 90fc763349..566f8a0bdd 100644
--- a/railties/guides/source/rails_application_templates.textile
+++ b/railties/guides/source/rails_application_templates.textile
@@ -148,7 +148,7 @@ The above creates +lib/tasks/bootstrap.rake+ with a +boot:strap+ rake task.
h4. generate(what, args)
-Runs the supplied rails generator with given arguments. For example, I love to scaffold some whenever I’m playing with Rails:
+Runs the supplied rails generator with given arguments.
generate(:scaffold, "person", "name:string", "address:text", "age:number")
@@ -176,12 +176,6 @@ You can also run rake tasks with a different Rails environment:
rake "db:migrate", :env => 'production'
-Or even use sudo:
-
-
-rake "gems:install", :sudo => true
-
-
h4. route(routing_code)
This adds a routing entry to the +config/routes.rb+ file. In above steps, we generated a person scaffold and also removed +public/index.html+. Now to make +PeopleController#index+ as the default page for the application:
--
cgit v1.2.3
From c80876f77880a97f94d2255ff9405bb080a6faa4 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Mon, 15 Aug 2011 16:26:37 +0100
Subject: Document Object#public_send
---
.../source/active_support_core_extensions.textile | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 781d3d08cd..8716e94bd9 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -452,6 +452,30 @@ Examples of +in?+:
NOTE: Defined in +active_support/core_ext/object/inclusion.rb+.
+h4. +public_send+
+
+This method is available by default in Ruby 1.9, and is backported to Ruby 1.8 by Active Support. Like the regular +send+ method, +public_send+ allows you to call a method when the name is not known until runtime. However, if the method is not public then a +NoMethodError+ exception will be raised.
+
+
+class Greeter
+ def hello(who)
+ "Hello " + who
+ end
+
+ private
+
+ def secret
+ "sauce"
+ end
+end
+
+greeter = Greeter.new
+greeter.public_send(:hello, 'Jim') # => "Hello Jim"
+greeter.public_send(:secret) # => NoMethodError
+
+
+NOTE: Defined in +active_support/core_ext/object/public_send.rb+.
+
h3. Extensions to +Module+
h4. +alias_method_chain+
--
cgit v1.2.3
From c0c5d5fd2e40f89fa56bf1c6785a392077f4263a Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Mon, 15 Aug 2011 21:46:21 +0530
Subject: assets guide - add info about require_directory, minor rephrasings
---
railties/guides/source/asset_pipeline.textile | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 8a4d61dc3a..a83226aa21 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -166,7 +166,7 @@ The more generic form can also be used but the asset path and class must both be
h4. Manifest Files and Directives
-Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, a page's load time is greatly reduced as there is not as many requests to make for each file.
+Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are not as many requests to make.
For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines:
@@ -176,9 +176,11 @@ For example, in the default Rails application there's a +app/assets/javascripts/
//= require_tree .
-In JavaScript files, directives begin with +//=+. In this case, the following file is using the +require+ directive and the +require_tree+ directive. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. An identical event takes place for the +jquery_ujs+ require
+In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets what are the files that we would like to require. Here, we are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. We need not supply the extensions explicitly. Sprockets will assume we are requiring a +.js+ file when done from within a +.js+ file.
-The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified.
+NOTE. In Rails 3.1, the +jquery.js+ and +jquery_ujs.js+ files are located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem.
+
+The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting).
There's also a default +app/assets/stylesheets/application.css+ file which contains these lines:
@@ -344,10 +346,10 @@ Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yu
The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your +if+ and +else+ statements to ternary operators where possible.
-The following line will invoke uglifier for JavaScript compression.
+The following line will invoke +uglifier+ for JavaScript compression.
-config.assets.js_compressor = :uglifier
+config.assets.js_compressor = :uglifier
The +config.assets.compress+ must be set to +true+ to enable JavaScript compression
--
cgit v1.2.3
From f7626ea38ebf1a6efdd8b059204aa2d22e096f39 Mon Sep 17 00:00:00 2001
From: JESii
Date: Mon, 15 Aug 2011 15:17:13 -0700
Subject: Updates to Asset Pipeline Guide
Grammar/syntax/style changes:
1. Changed all 'we' to 'you'
2. Corrected typos
3. Make consistent styline (e.g., dashes & double-dash usage)
4. Change use of future tense (will...) to present tense (easier to read).
---
railties/guides/source/asset_pipeline.textile | 90 +++++++++++++--------------
1 file changed, 45 insertions(+), 45 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index a83226aa21..74a9e497f2 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -1,6 +1,6 @@
h2. Asset Pipeline
-This guide will cover the ideology of the asset pipeline introduced in Rails 3.1.
+This guide covers the ideology of the asset pipeline introduced in Rails 3.1.
By referring to this guide you will be able to:
* Understand what the asset pipeline is and what it does
@@ -19,7 +19,7 @@ Prior to Rails 3.1 these features were added through third-party Ruby libraries
By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf.
-In new Rails 3.1 application the asset pipeline is enable by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition:
+In new Rails 3.1 application the asset pipeline is enabled by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition:
config.assets.enabled = false
@@ -30,17 +30,17 @@ It is recommended that you use the defaults for all new apps.
h4. Main Features
-The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser needs to make to render a web page. While Rails already has a feature to concatenate these types of asset--by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+--, many people do not use it.
+The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assetsi -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it.
-The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered.
+The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production, an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered.
-The second feature is to minify or compress. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own.
+The second feature is to minify or compress assets. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own.
The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for JavaScript, and ERB for both.
h4. What is Fingerprinting and Why Should I Care?
-Fingerprinting is a technique where the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file.
+Fingerprinting is a technique whereby the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file.
When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cachebusting_.
@@ -52,7 +52,7 @@ global.css => global-908e25f4bf641868d8683022a5b62f54.css
This is the strategy adopted by the Rails asset pipeline.
-Rails old strategy was to append a query string to every asset linked with a built-in helper. In the source the generated code looked like this:
+Rails' old strategy was to append a query string to every asset linked with a built-in helper. In the source the generated code looked like this:
/stylesheets/global.css?1309495796
@@ -73,7 +73,7 @@ This has several disadvantages:
The other problem is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed.
-Fingerprinting avoids all these problems by ensuring filenames are consistent based on the content.
+Fingerprinting avoids all these problems by ensuring filenames are consistent based on their content.
More reading:
@@ -83,11 +83,11 @@ More reading:
h3. How to Use the Asset Pipeline
-In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory will be served by the Sprockets middleware included in the sprockets gem.
+In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory are served by the Sprockets middleware included in the sprockets gem.
This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served.
-When a scaffold or controller is generated for the application, Rails will also generate a JavaScript file (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller.
+When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-script+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller.
For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
@@ -101,13 +101,13 @@ Assets can be placed inside an application in one of three locations: +app/asset
+vendor/assets+ is for assets that are owned by outside entities, such as code for JavaScript plugins.
-All subdirectories that exist within these three locations will be added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths will be looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served.
+All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served.
h4. Coding Links to Assets
-To access assets, we can use the same tags that we are generally familiar with:
+To access assets, you use the same tags that you are generally familiar with:
-Sprockets does not add any new methods to require your assets, we still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+.
+Sprockets does not add any new methods to require your assets, you still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+.
<%= stylesheet_link_tag "application" %>
@@ -126,29 +126,29 @@ Images can be organized into directories if required, and they can be accessed b
<%= image_tag "icons/rails.png" %>
-Providing that assets are enabled within our application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served.
+Providing that assets are enabled within your application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file is served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file is served.
-Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ will also be picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide.
+Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is also picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide.
-Otherwise, Sprockets will look through the available paths until it finds a file that matches the name and then will serve it, first looking in the application's assets directories and then falling back to the various engines of the application.
+Otherwise, Sprockets looks through the available paths until it finds a file that matches the name and then serves it, first looking in the application's assets directories and then falling back to the various engines of the application.
-If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme - a method of embedding the image data directly into the CSS file - you can use the +asset_data_uri+ helper.
+If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper.
#logo { background: url(<%= asset_data_uri 'logo.png' %>)
-This will insert a correctly formatted data URI into the CSS source.
+This inserts a correctly-formatted data URI into the CSS source.
h5. CSS and ERB
-If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+ then you can use the +asset_path+ helper in your CSS rules:
+If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules:
.class{background-image:<%= asset_path 'image.png' %>}
-This will write the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file then that path will be referenced.
+This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced.
Note that the closing tag cannot be of the style +-%>+.
@@ -166,7 +166,7 @@ The more generic form can also be used but the asset path and class must both be
h4. Manifest Files and Directives
-Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are not as many requests to make.
+Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make.
For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines:
@@ -176,7 +176,7 @@ For example, in the default Rails application there's a +app/assets/javascripts/
//= require_tree .
-In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets what are the files that we would like to require. Here, we are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. We need not supply the extensions explicitly. Sprockets will assume we are requiring a +.js+ file when done from within a +.js+ file.
+In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets the files that you wish to require. Here, you are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. You need not supply the extensions explicitly. Sprockets assumes you are requiring a +.js+ file when done from within a +.js+ file.
NOTE. In Rails 3.1, the +jquery.js+ and +jquery_ujs.js+ files are located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem.
@@ -191,13 +191,13 @@ There's also a default +app/assets/stylesheets/application.css+ file which conta
*/
-The directives that work in the JavaScript files will also work in stylesheets, obviously including stylesheets rather than JavaScript files. The +require_tree+ directive here works the same way as the JavaScript one, requiring all stylesheets from the current directory.
+The directives that work in the JavaScript files also work in stylesheets, obviously including stylesheets rather than JavaScript files. The +require_tree+ directive here works the same way as the JavaScript one, requiring all stylesheets from the current directory.
-In this example +require_self+ is used. This will put the CSS contained within the file (if any) at the top of any other CSS in this file unless +require_self+ is specified after another +require+ directive.
+In this example +require_self+ is used. This puts the CSS contained within the file (if any) at the top of any other CSS in this file unless +require_self+ is specified after another +require+ directive.
You can have as many manifest files as you need. For example the +admin.css+ and +admin.js+ manifest could contain the JS and CSS files that are used for the admin section of an application.
-For some assets (like CSS) the compiled order is important. You can specify individual files and they will be compiled in the order specified:
+For some assets (like CSS) the compiled order is important. You can specify individual files and they are compiled in the order specified:
/* ...
@@ -210,36 +210,36 @@ For some assets (like CSS) the compiled order is important. You can specify indi
h4. Preprocessing
-The file extensions used on an asset will determine what preprocessing will be applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file will be generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file.
+The file extensions used on an asset determine what preprocessing is applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file are generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file.
-When these files are requested, they will be processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively.
+When these files are requested, they are processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively.
-Additional layers of pre-processing can be requested by adding other extensions, where each extension will be processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ would first be processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file - +app/assets/javascripts/projects.js.coffee.erb+ would be process as ERB, CoffeeScript and served as JavaScript.
+Additional layers of pre-processing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ is first processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file -- +app/assets/javascripts/projects.js.coffee.erb+ is processed as ERB, CoffeeScript and served as JavaScript.
-Keep in mind that the order of these pre-processors is important. For example, if we called our JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it would be processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore we would run into problems.
+Keep in mind that the order of these pre-processors is important. For example, if you called your JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it is processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems.
h3. In Development
In the development environment assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response.
-If any of the files in the manifest have changed between requests, the server will respond with a new compiled file.
+If any of the files in the manifest have changed between requests, the server responds with a new compiled file.
h4. Debugging Assets
-You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets will expand the lines which load the assets. For example, if we had an +app/assets/javascripts/application.js+ file containing these lines:
+You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines:
//= require "projects"
//= require "tickets"
-By default, this would only render this line when used with +<%= javascript_include_tag "application" %>+ in a view or layout:
+By default, this only renders this line when used with +<%= javascript_include_tag "application" %>+ in a view or layout:
-When the +debug_assets+ parameter is set, this line will be expanded out into three separate lines, separating out the combined file into their parts.
+When the +debug_assets+ parameter is set, this line is expanded out into three separate lines, separating out the combined file into their parts.
@@ -253,7 +253,7 @@ h3. In Production
In the production environment, assets are served slightly differently.
-On the first request the assets are compiled and cached as described above, however the manifest names are altered to include an MD5 hash. Files names typically will look like these:
+On the first request the assets are compiled and cached as described above, however the manifest names are altered to include an MD5 hash. Files names typically look like these:
/assets/application-908e25f4bf641868d8683022a5b62f54.js
@@ -270,7 +270,7 @@ h4. Precompiling Assets
Even though assets are served by Rack::Cache with far-future headers, in high traffic sites this may not be fast enough.
-Rails comes bundled with a rake task to compile the manifests to files on disc. These are located in the +public/assets+ directory where they will be served by your web server instead of the Rails application.
+Rails comes bundled with a rake task to compile the manifests to files on disc. These are located in the +public/assets+ directory where they are served by your web server instead of the Rails application.
The rake task is:
@@ -278,7 +278,7 @@ The rake task is:
rake assets:precompile
-Capistrano (v2.8.0+) has a recipe to to handle this in deployment. Add the following line to +Capfile+:
+Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the following line to +Capfile+:
load 'deploy/assets'
@@ -286,9 +286,9 @@ load 'deploy/assets'
This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this folder you'll need to write your own deployment task.
-It is important for this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page.
+It is important that this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page.
-The default matcher for compiling files will include +application.js+, +application.css+ and all files that do not end in +js+ or +css+:
+The default matcher for compiling files includes +application.js+, +application.css+ and all files that do not end in +js+ or +css+:
[ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
@@ -320,7 +320,7 @@ For Apache:
TODO: NGINX instructions
-When files are precompiled Sprockets also creates "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used:
+When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used:
TODO: Apache instructions
@@ -332,7 +332,7 @@ h4. CSS Compression
There is currently one option for compressing CSS - YUI. This Gem extends the CSS syntax and offers minification.
-The following line will enable YUI compression, and requires the +yui-compressor+ gem.
+The following line enables YUI compression, and requires the +yui-compressor+ gem.
config.assets.css_compressor = :yui
@@ -344,9 +344,9 @@ h4. JavaScript
Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively.
-The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your +if+ and +else+ statements to ternary operators where possible.
+The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compresses your code by removing white space and other magical things like changing your +if+ and +else+ statements to ternary operators where possible.
-The following line will invoke +uglifier+ for JavaScript compression.
+The following line invokes +uglifier+ for JavaScript compression.
config.assets.js_compressor = :uglifier
@@ -356,7 +356,7 @@ The +config.assets.compress+ must be set to +true+ to enable JavaScript compress
h4. Using Your Own Compressor
-The compressor config settings for CSS and JavaScript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string.
+The compressor config settings for CSS and JavaScript also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string.
class Transformer
@@ -366,7 +366,7 @@ class Transformer
end
-To enable this pass a +new+ Object to the config option in +application.rb+:
+To enable this, pass a +new+ Object to the config option in +application.rb+:
config.assets.css_compressor = Transformer.new
@@ -387,7 +387,7 @@ This is a handy option if you have any existing project (pre Rails 3.1) that alr
h4. X-Sendfile Headers
-The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. This option is off be default, but can be enabled if your server supports it. When enabled, this passes responsibility for serving the file to the web server, which is faster.
+The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. This option is off by default, but can be enabled if your server supports it. When enabled, this passes responsibility for serving the file to the web server, which is faster.
Apache and nginx support this option which is enabled in config/environments/production.rb.
--
cgit v1.2.3
From 583d7c15c301f15f1e997a06e15b55a2e7bf794f Mon Sep 17 00:00:00 2001
From: Jacob Mattingley
Date: Mon, 15 Aug 2011 16:00:53 -0700
Subject: Fixed mistakes in layouts/rendering guide about yield
yield(:unspecified_block) actually returns true even if :unspecified_block never
exists. This means you can't use the form yield(:unspecified_block) or yield.
---
railties/guides/source/layouts_and_rendering.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 57485e8986..87ba8ab82d 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -1179,14 +1179,14 @@ On pages generated by +NewsController+, you want to hide the top menu and add a
<% end %>
<% content_for :content do %>
Right menu items here
- <%= yield(:news_content) or yield %>
+ <%= content_for?(:news_content) ? yield(:news_content) : yield %>
<% end %>
<%= render :template => 'layouts/application' %>
That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div.
-There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +yield(:news_content) or yield+ with simply +yield+.
+There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +content_for?(:news_content) ? yield(:news_content) : yield+ with simply +yield+.
h3. Changelog
--
cgit v1.2.3
From 308595739c32609ac5b167ecdc6cb6cb4ec6c81f Mon Sep 17 00:00:00 2001
From: Sebastian Martinez
Date: Mon, 15 Aug 2011 20:20:28 -0300
Subject: Document Hash#extract!.
---
.../guides/source/active_support_core_extensions.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 781d3d08cd..a672b17e4a 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -2696,6 +2696,18 @@ hash # => {:a => 1}
NOTE: Defined in +active_support/core_ext/hash/slice.rb+.
+h4. Extracting
+
+The method +extract!+ removes and returns the key/value pairs matching the given keys.
+
+
+hash = {:a => 1, :b => 2}
+rest = hash.extract!(:a) # => {:a => 1}
+hash # => {:b => 2}
+
+
+NOTE: Defined in +active_support/core_ext/hash/slice.rb+.
+
h4. Indifferent Access
The method +with_indifferent_access+ returns an +ActiveSupport::HashWithIndifferentAccess+ out of its receiver:
--
cgit v1.2.3
From bd4800d614eb7060354a6f9fd8a749a7e7f046a8 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 16 Aug 2011 14:57:36 +0530
Subject: document Array#append and Array#prepend methods in AS guide
---
.../source/active_support_core_extensions.textile | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index a672b17e4a..e1fa374aca 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -2069,6 +2069,30 @@ shape_types = [Circle, Square, Triangle].sample(2)
NOTE: Defined in +active_support/core_ext/array/random_access.rb+.
+h4. Adding Elements
+
+h5. +prepend+
+
+This method is an alias of Array#unshift.
+
+
+%w(a b c d).prepend('e') # => %w(e a b c d)
+[].prepend(10) # => [10]
+
+
+NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+.
+
+h5. +append+
+
+This method is an alias of Array#<<.
+
+
+%w(a b c d).append('e') # => %w(a b c d e)
+[].append([1,2]) # => [[1,2]]
+
+
+NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+.
+
h4. Options Extraction
When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets:
--
cgit v1.2.3
From c5f97b5063d1d60341f9e984f29a3b9812fb4c7e Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Tue, 16 Aug 2011 13:12:07 -0400
Subject: Fix formatting of active_record_validations_callbacks.textile so
guide will render properly at
http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html#displaying-validation-errors-in-the-view
---
railties/guides/source/active_record_validations_callbacks.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 977e736d25..aba3224ba7 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -751,8 +751,6 @@ class Person < ActiveRecord::Base
end
-
-
h4. +errors.clear+
The +clear+ method is used when you intentionally want to clear all the messages in the +errors+ collection. Of course, calling +errors.clear+ upon an invalid object won't actually make it valid: the +errors+ collection will now be empty, but the next time you call +valid?+ or any method that tries to save this object to the database, the validations will run again. If any of the validations fail, the +errors+ collection will be filled again.
@@ -799,6 +797,7 @@ h3. Displaying Validation Errors in the View
Rails maintains an official plugin that provides helpers to display the error messages of your models in your view templates. You can install it as a plugin or as a Gem.
h4. Installing as a plugin
+
$ rails plugin install git://github.com/joelmoss/dynamic_form.git
@@ -806,6 +805,7 @@ $ rails plugin install git://github.com/joelmoss/dynamic_form.git
h4. Installing as a Gem
Add this line in your Gemfile:
+
gem "dynamic_form"
--
cgit v1.2.3
From 53a13083ecc7f99ff04d3fe54f8cb1d68e486aac Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Tue, 16 Aug 2011 10:34:18 -0700
Subject: AS guide: document in Module#delegate that the method must be public
in the target
---
railties/guides/source/active_support_core_extensions.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 8716e94bd9..38920c2edb 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -888,7 +888,9 @@ end
It is shorter, and the intention more obvious.
-The macro accepts several methods:
+The method must be public in the target.
+
+The +delegate+ macro accepts several methods:
delegate :name, :age, :address, :twitter, :to => :profile
--
cgit v1.2.3
From 7ff894dcc75b46274e20a20c26b679e204e6c82b Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Tue, 16 Aug 2011 22:48:01 -0400
Subject: Fix spacing in plugins.textile to fix html rendering and remove extra
whitespace from security.textile
---
railties/guides/source/plugins.textile | 2 ++
railties/guides/source/security.textile | 1 -
2 files changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile
index 188423861d..d3f9783fa6 100644
--- a/railties/guides/source/plugins.textile
+++ b/railties/guides/source/plugins.textile
@@ -386,6 +386,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle
Run +rake+ one final time and you should see:
+
7 tests, 7 assertions, 0 failures, 0 errors, 0 skips
@@ -426,6 +427,7 @@ require 'yaffle'
You can test this by changing to the Rails application that you added the plugin to and starting a rails console. Once in the
console we can check to see if the String has an instance method of to_squawk.
+
$ cd my_app
$ rails console
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index 1f6ff88c1f..04d1d0bda8 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -80,7 +80,6 @@ This will also be a good idea, if you modify the structure of an object and old
* _(highlight)Critical data should not be stored in session_. If the user clears his cookies or closes the browser, they will be lost. And with a client-side session storage, the user can read the data.
-
h4. Session Storage
-- _Rails provides several storage mechanisms for the session hashes. The most important are ActiveRecordStore and CookieStore._
--
cgit v1.2.3
From f302370c0527cd5f24889e7068134e59b65b40f1 Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Tue, 16 Aug 2011 22:59:36 -0400
Subject: Fix ruby typo to correctly render code block in initializer.textile
---
railties/guides/source/initialization.textile | 3 +--
railties/guides/source/migrations.textile | 1 +
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 49d7513448..b93c4f35ac 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -761,7 +761,6 @@ def subclasses
end
-
The +config+ method used at the top of +I18n::Railtie+ is defined on +Rails::Railtie+ and is defined like this:
@@ -848,7 +847,7 @@ The +Collection+ class in +railties/lib/rails/initializable.rb+ inherits from +A
The +initializers_chain+ method referenced in the +initializers_for+ method is defined like this:
-
+
def initializers_chain
initializers = Collection.new
ancestors.reverse_each do | klass |
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 9da12e2e18..6fcc3cf4a2 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -300,6 +300,7 @@ change_table :products do |t|
t.rename :upccode, :upc_code
end
+
removes the +description+ and +name+ columns, creates a +part_number+ column and adds an index on it. Finally it renames the +upccode+ column. This is the same as doing
--
cgit v1.2.3
From 6eadf5d192f208d21f876603a0a1607fa80bb68a Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Tue, 16 Aug 2011 23:04:16 -0400
Subject: Fix typo in i18n.textile header and remove extra whitespace.
---
railties/guides/source/i18n.textile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 0c8e4e974d..4b6b08bcec 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -1,4 +1,4 @@
-lh2. Rails Internationalization (I18n) API
+h2. Rails Internationalization (I18n) API
The Ruby I18n (shorthand for _internationalization_) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for *translating your application to a single custom language* other than English or for *providing multi-language support* in your application.
@@ -796,7 +796,6 @@ h5. Active Support Methods
* +Array#to_sentence+ uses format settings as given in the "support.array":https://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L30 scope.
-
h3. Customize your I18n Setup
h4. Using Different Backends
--
cgit v1.2.3
From 6783ce0de4511e2568765f2e4919758d70690391 Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Tue, 16 Aug 2011 23:35:40 -0400
Subject: Updates to remove extra whitespaces and notably fix a whitespace
issue with ajax_on_rails causing a code block not to render the entire block
properly.
---
railties/guides/source/action_view_overview.textile | 1 -
railties/guides/source/active_model_basics.textile | 1 -
railties/guides/source/active_record_basics.textile | 1 -
railties/guides/source/ajax_on_rails.textile | 8 +-------
railties/guides/source/api_documentation_guidelines.textile | 2 --
railties/guides/source/asset_pipeline.textile | 4 ----
railties/guides/source/caching_with_rails.textile | 2 --
railties/guides/source/contributing_to_ruby_on_rails.textile | 1 -
railties/guides/source/form_helpers.textile | 1 -
railties/guides/source/getting_started.textile | 2 --
10 files changed, 1 insertion(+), 22 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index d40e0840ce..5a1e8b1247 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -478,7 +478,6 @@ javascript_include_tag :monkey # =>
-
h5. register_stylesheet_expansion
Register one or more stylesheet files to be included when symbol is passed to +stylesheet_link_tag+. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in +public/stylesheets+.
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index f3a2b2edbc..3c19fb5177 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -168,7 +168,6 @@ Track what was the previous value of the attribute.
person.first_name_was #=> "First Name"
-
Track both previous and current value of the changed attribute. Returns an array if changed else returns nil
#attr_name_change
diff --git a/railties/guides/source/active_record_basics.textile b/railties/guides/source/active_record_basics.textile
index 3e46e7df9f..cab8c80866 100644
--- a/railties/guides/source/active_record_basics.textile
+++ b/railties/guides/source/active_record_basics.textile
@@ -204,7 +204,6 @@ Likewise, once retrieved an Active Record object can be destroyed which removes
user.destroy
-
h3. Validations
Active Record allows you to validate the state of a model before it gets written into the database. There are several methods that you can use to check your models and validate that an attribute value is not empty, is unique and not already in the database, follows a specific format and many more. You can learn more about validations in the "Active Record Validations and Callbacks guide":active_record_validations_callbacks.html#validations-overview.
diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile
index 8b72e20c33..77f7661deb 100644
--- a/railties/guides/source/ajax_on_rails.textile
+++ b/railties/guides/source/ajax_on_rails.textile
@@ -24,16 +24,12 @@ h4. Standard HTML communication vs AJAX
How do 'standard' and AJAX requests differ, why does this matter for understanding AJAX on Rails (tie in for *_remote helpers, the next section)
-
-
-
-
-
h3. Built-in Rails Helpers
Rails' JavaScript framework of choice is "Prototype":http://www.prototypejs.org. Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views.
To get access to these helpers, all you have to do is to include the prototype framework in your pages - typically in your master layout, application.html.erb - like so:
+
javascript_include_tag 'prototype'
@@ -59,7 +55,6 @@ link_to_remote "Add to cart",
* The very first parameter, a string, is the text of the link which appears on the page.
-
* The second parameter, the +options+ hash is the most interesting part as it has the AJAX specific stuff:
** *:url* This is the only parameter that is always required to generate the simplest remote link (technically speaking, it is not required, you can pass an empty +options+ hash to +link_to_remote+ - but in this case the URL used for the POST request will be equal to your current URL which is probably not your intention). This URL points to your AJAX action handler. The URL is typically specified by Rails REST view helpers, but you can use the +url_for+ format too.
** *:update* Specifying a DOM id of the element we would like to update. The above example demonstrates the simplest way of accomplishing this - however, we are in trouble if the server responds with an error message because that will be injected into the page too! However, Rails has a solution for this situation:
@@ -193,7 +188,6 @@ end
What happens here is that by specifying the Content-Type header variable, we instruct the browser to evaluate the text we are sending over (rather than displaying it as plain text, which is the default behavior).
-
h3. Testing JavaScript
JavaScript testing reminds me the definition of the world 'classic' by Mark Twain: "A classic is something that everybody wants to have read and nobody wants to read." It's similar with JavaScript testing: everyone would like to have it, yet it's not done by too much developers as it is tedious, complicated, there is a proliferation of tools and no consensus/accepted best practices, but we will nevertheless take a stab at it:
diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile
index 9c4df2d6b8..3ebf0e10f1 100644
--- a/railties/guides/source/api_documentation_guidelines.textile
+++ b/railties/guides/source/api_documentation_guidelines.textile
@@ -106,7 +106,6 @@ routes.rb # NO
RAILS_ROOT/config/routes.rb # NO
-
h3. Fonts
h4. Fixed-width Font
@@ -188,4 +187,3 @@ self.class_eval %{
h3. Changelog
* July 17, 2010: ported from the docrails wiki and revised by "Xavier Noria":credits.html#fxn
-
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 74a9e497f2..8094ba18f2 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -27,7 +27,6 @@ config.assets.enabled = false
It is recommended that you use the defaults for all new apps.
-
h4. Main Features
The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assetsi -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it.
@@ -80,7 +79,6 @@ More reading:
* "Optimize caching":http://code.google.com/speed/page-speed/docs/caching.html
* "Revving Filenames: don’t use querystring":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
-
h3. How to Use the Asset Pipeline
In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory are served by the Sprockets middleware included in the sprockets gem.
@@ -324,7 +322,6 @@ When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.
TODO: Apache instructions
-
h3. Customizing the Pipeline
@@ -372,7 +369,6 @@ To enable this, pass a +new+ Object to the config option in +application.rb+:
config.assets.css_compressor = Transformer.new
-
h4. Changing the _assets_ Path
The public path that Sprockets uses by default is +/assets+.
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index ae56911441..693303950d 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -404,7 +404,6 @@ h3. Further reading
* "Scaling Rails Screencasts":http://railslab.newrelic.com/scaling-rails
-
h3. Changelog
* Feb 17, 2011: Document 3.0.0 changes to ActiveSupport::Cache
@@ -415,4 +414,3 @@ h3. Changelog
* December 27, 2008: Typo fixes
* November 23, 2008: Incremental updates with various suggested changes and formatting cleanup
* September 15, 2008: Initial version by Aditya Chadha
-
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index e6ec061c9a..4706725bb6 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -104,7 +104,6 @@ $ cd railties
$ TEST_DIR=generators rake test
-
h4. Warnings
The test suite runs with warnings enabled. Ideally Ruby on Rails should issue no warning, but there may be a few, and also some from third-party libraries. Please ignore (or fix!) them if any, and submit patches that do not issue new warnings.
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index bf2a7369a7..c277f5723a 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -342,7 +342,6 @@ output:
When parsing POSTed data, Rails will take into account the special +_method+ parameter and acts as if the HTTP method was the one specified inside it ("PUT" in this example).
-
h3. Making Select Boxes with Ease
Select boxes in HTML require a significant amount of markup (one +OPTION+ element for each option to choose from), therefore it makes the most sense for them to be dynamically generated.
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 3cca383616..092ca90a30 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -116,7 +116,6 @@ need to know anything about them to continue with this guide.
* Active Support
* Railties
-
h5. Action Pack
Action Pack is a single gem that contains Action Controller, Action View and
@@ -1633,7 +1632,6 @@ Authentication challenge
!images/challenge.png(Basic HTTP Authentication Challenge)!
-
h3. Building a Multi-Model Form
Another feature of your average blog is the ability to tag posts. To implement
--
cgit v1.2.3
From 3b5eb11664b8257d35dced58f1d65e34fa4a6c1f Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Wed, 17 Aug 2011 14:37:27 -0700
Subject: fixes generation of the AR querying guide
---
railties/guides/source/active_record_querying.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 8ea06d28aa..4e77a6e803 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -560,6 +560,7 @@ Client.where("orders_count > 10").order(:name).reverse_order
The SQL that would be executed:
+
SELECT * FROM clients WHERE orders_count > 10 ORDER BY name DESC
@@ -571,6 +572,7 @@ Client.where("orders_count > 10").reverse_order
The SQL that would be executed:
+
SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC
@@ -621,8 +623,6 @@ You're then responsible for dealing with the conflict by rescuing the exception
NOTE: You must ensure that your database schema defaults the +lock_version+ column to +0+.
-
-
This behavior can be turned off by setting ActiveRecord::Base.lock_optimistically = false.
To override the name of the +lock_version+ column, +ActiveRecord::Base+ provides a class method called +set_locking_column+:
--
cgit v1.2.3
From 129ad7226d32b19fac1aca2ebccd570b3382d6d5 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 20 Aug 2011 00:17:37 +0530
Subject: mailer guide: fixes indentation, and use fixed width fonts wherever
necessary
---
.../guides/source/action_mailer_basics.textile | 57 ++++++++++------------
1 file changed, 26 insertions(+), 31 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 0941b06cfe..142b9dba7e 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -8,7 +8,7 @@ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not
h3. Introduction
-Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from +ActionMailer::Base+ and live in +app/mailers+. Those mailers have associated views that appear alongside controller views in +app/views+.
+Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from +ActionMailer::Base+ and live in +app/mailers+. Those mailers have associated views that appear alongside controller views in +app/views+.
h3. Sending Emails
@@ -48,10 +48,8 @@ class UserMailer < ActionMailer::Base
def welcome_email(user)
@user = user
@url = "http://example.com/login"
- mail(:to => user.email,
- :subject => "Welcome to My Awesome Site")
+ mail(:to => user.email, :subject => "Welcome to My Awesome Site")
end
-
end
@@ -142,17 +140,17 @@ end
This provides a much simpler implementation that does not require the registering of observers and the like.
-The method +welcome_email+ returns a Mail::Message object which can then just be told +deliver+ to send itself out.
+The method +welcome_email+ returns a Mail::Message object which can then just be told +deliver+ to send itself out.
NOTE: In previous versions of Rails, you would call +deliver_welcome_email+ or +create_welcome_email+. This has been deprecated in Rails 3.0 in favour of just calling the method name itself.
-WARNING: Sending out one email should only take a fraction of a second, if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like delayed job.
+WARNING: Sending out an email should only take a fraction of a second, but if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like Delayed Job.
h4. Auto encoding header values
Action Mailer now handles the auto encoding of multibyte characters inside of headers and bodies.
-If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and ActionMailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII.
+If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and Action Mailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII.
For more complex examples such as defining alternate character sets or self encoding text first, please refer to the Mail library.
@@ -213,7 +211,7 @@ NOTE: If you specify an encoding, Mail will assume that your content is already
h5. Making Inline Attachments
-ActionMailer 3.0 makes inline attachments, which involved a lot of hacking in pre 3.0 versions, much simpler and trivial as they should be.
+Action Mailer 3.0 makes inline attachments, which involved a lot of hacking in pre 3.0 versions, much simpler and trivial as they should be.
* Firstly, to tell Mail to turn an attachment into an inline attachment, you just call #inline on the attachments method within your Mailer:
@@ -245,15 +243,15 @@ h5. Sending Email To Multiple Recipients
It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas.
- class AdminMailer < ActionMailer::Base
- default :to => Admin.all.map(&:email),
- :from => "notification@example.com"
+class AdminMailer < ActionMailer::Base
+ default :to => Admin.all.map(&:email),
+ :from => "notification@example.com"
- def new_registration(user)
- @user = user
- mail(:subject => "New User Signup: #{@user.email}")
- end
+ def new_registration(user)
+ @user = user
+ mail(:subject => "New User Signup: #{@user.email}")
end
+end
The same format can be used to set carbon copy (Cc:) and blind carbon copy (Bcc:) recipients, by using the :cc and :bcc keys respectively.
@@ -264,12 +262,11 @@ Sometimes you wish to show the name of the person instead of just their email ad
to format the email address in the format "Name <email>".
- def welcome_email(user)
- @user = user
- email_with_name = "#{@user.name} <#{@user.email}>"
- mail(:to => email_with_name,
- :subject => "Welcome to My Awesome Site")
- end
+def welcome_email(user)
+ @user = user
+ email_with_name = "#{@user.name} <#{@user.email}>"
+ mail(:to => email_with_name, :subject => "Welcome to My Awesome Site")
+end
h4. Mailer Views
@@ -289,9 +286,7 @@ class UserMailer < ActionMailer::Base
:subject => "Welcome to My Awesome Site",
:template_path => 'notifications',
:template_name => 'another')
- end
end
-
end
@@ -461,14 +456,14 @@ h3. Action Mailer Configuration
The following configuration options are best made in one of the environment files (environment.rb, production.rb, etc...)
-|template_root|Determines the base from which template references will be made.|
-|logger|Generates information on the mailing run if available. Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.|
-|smtp_settings|Allows detailed configuration for :smtp delivery method:
:address - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
:port - On the off chance that your mail server doesn't run on port 25, you can change it.
:domain - If you need to specify a HELO domain, you can do it here.
:user_name - If your mail server requires authentication, set the username in this setting.
:password - If your mail server requires authentication, set the password in this setting.
:authentication - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5.
|
-|sendmail_settings|Allows you to override options for the :sendmail delivery method.
:location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail.
:arguments - The command line arguments to be passed to sendmail. Defaults to -i -t.
|
-|raise_delivery_errors|Whether or not errors should be raised if the email fails to be delivered.|
-|delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.|
-|perform_deliveries|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.|
-|deliveries|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.|
+|+template_root+|Determines the base from which template references will be made.|
+|+logger+|Generates information on the mailing run if available. Can be set to +nil+ for no logging. Compatible with both Ruby's own +Logger+ and +Log4r+ loggers.|
+|+smtp_settings+|Allows detailed configuration for :smtp delivery method:
:address - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
:port - On the off chance that your mail server doesn't run on port 25, you can change it.
:domain - If you need to specify a HELO domain, you can do it here.
:user_name - If your mail server requires authentication, set the username in this setting.
:password - If your mail server requires authentication, set the password in this setting.
:authentication - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5.
|
+|+sendmail_settings+|Allows you to override options for the :sendmail delivery method.
:location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail.
:arguments - The command line arguments to be passed to sendmail. Defaults to -i -t.
|
+|+raise_delivery_errors+|Whether or not errors should be raised if the email fails to be delivered.|
+|+delivery_method+|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.|
+|+perform_deliveries+|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.|
+|+deliveries+|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.|
h4. Example Action Mailer Configuration
--
cgit v1.2.3
From 0b3b91cdcdfd54fc4a9e9bcb6be95ff487724e25 Mon Sep 17 00:00:00 2001
From: Sebastian Martinez
Date: Fri, 19 Aug 2011 19:45:55 -0300
Subject: Document debugging assets set by default for dev and test envs in the
asset_pipeline guide.
---
railties/guides/source/asset_pipeline.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 8094ba18f2..34ab00e80d 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -247,6 +247,8 @@ When the +debug_assets+ parameter is set, this line is expanded out into three s
This allows the individual parts of an asset to be rendered and debugged separately.
+NOTE. Assets debugging is turned on by default in development and test environments.
+
h3. In Production
In the production environment, assets are served slightly differently.
--
cgit v1.2.3
From 7444c620cfa88d4ffade121bbbad0d4699c36f8a Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 20 Aug 2011 23:27:31 +0530
Subject: minor change in the 3.1 release notes
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index ba36735a0b..087926f98d 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -115,7 +115,7 @@ h4. Action Controller
* URL parameters which return +nil+ for +to_param+ are now removed from the query string.
-* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb.
+* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized in config/initializers/wrap_parameters.rb.
* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to +false+ will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
--
cgit v1.2.3
From 95bece9155c46a2273a3febc3a2e176b8c15df8f Mon Sep 17 00:00:00 2001
From: Joost Baaij
Date: Mon, 22 Aug 2011 00:10:01 +0300
Subject: Removed my name from the changelog as the amount of blogspam became
ridiculous. When will docrails be back? :-p
---
railties/guides/source/getting_started.textile | 1 -
1 file changed, 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 092ca90a30..755f59f8f9 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1890,7 +1890,6 @@ h3. Changelog
* April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com
* April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com
-* August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl
* July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com
* May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
* April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
--
cgit v1.2.3
From 18b2223b3290c4b3daa310edfc06b4d51161c312 Mon Sep 17 00:00:00 2001
From: "Andrey A.I. Sitnik"
Date: Mon, 22 Aug 2011 09:36:36 +1100
Subject: Allow to debug assets by config.assets.debug
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 34ab00e80d..012149c40e 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -224,7 +224,7 @@ If any of the files in the manifest have changed between requests, the server re
h4. Debugging Assets
-You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines:
+You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL or set +config.assets.debug+ and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines:
//= require "projects"
--
cgit v1.2.3
From 44f0d94469fb6c5d400776c3307b16fb8e4d1eb1 Mon Sep 17 00:00:00 2001
From: Andrey Ognevsky
Date: Sun, 21 Aug 2011 01:25:11 +0300
Subject: Add Destroy Alias
* Added destroy alias to rails generator
* add alias info for destroy command
* Updated command line guides
---
railties/guides/source/command_line.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index 6d5132a1bf..f6b33d283c 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -325,6 +325,8 @@ h4. +rails destroy+
Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it.
+You can also use the alias "d" to invoke the destroy command: rails d.
+
$ rails generate model Oops
exists app/models/
--
cgit v1.2.3
From c46befbce300722650e324047a9342f628acc36d Mon Sep 17 00:00:00 2001
From: Joost Baaij
Date: Tue, 23 Aug 2011 14:17:29 +0200
Subject: Revert "Removed my name from the changelog as the amount of blogspam
became ridiculous.
"
This reverts commit 95bece9155c46a2273a3febc3a2e176b8c15df8f.
---
railties/guides/source/getting_started.textile | 1 +
1 file changed, 1 insertion(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 755f59f8f9..092ca90a30 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1890,6 +1890,7 @@ h3. Changelog
* April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com
* April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com
+* August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl
* July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com
* May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
* April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
--
cgit v1.2.3
From 707378c4892a4666c8b7ed73bef577338bca3c38 Mon Sep 17 00:00:00 2001
From: Joost Baaij
Date: Tue, 23 Aug 2011 14:18:06 +0200
Subject: removed the link to my blog to help stop endless comments
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 092ca90a30..d2bfcfdbb4 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1890,7 +1890,7 @@ h3. Changelog
* April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com
* April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com
-* August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl
+* August 30, 2010: Minor editing after Rails 3 release by Joost Baaij
* July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com
* May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
* April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
--
cgit v1.2.3
From 11146f1485ac83950c1079a458bd5fbae6ab405b Mon Sep 17 00:00:00 2001
From: Brian Morearty
Date: Tue, 23 Aug 2011 21:34:43 -0700
Subject: Remove extra word from sentence in initialization guide.
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index b93c4f35ac..9cc4dd5f04 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -1,6 +1,6 @@
h2. The Rails Initialization Process
-This guide explains the internals of the initialization process in Rails works as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers.
+This guide explains the internals of the initialization process in Rails as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers.
* Using +rails server+
* Using Passenger
--
cgit v1.2.3
From a5e925c1d35ff10a22a98841f6a02925d4263947 Mon Sep 17 00:00:00 2001
From: Bogdan Gusiev
Date: Wed, 24 Aug 2011 10:25:29 +0300
Subject: Add strict validation example to guides
---
railties/guides/source/active_model_basics.textile | 7 +++++--
railties/guides/source/active_record_validations_callbacks.textile | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index f3a2b2edbc..7d435456bd 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -184,20 +184,23 @@ Validations module adds the ability to class objects to validate them in Active
class Person
include ActiveModel::Validations
- attr_accessor :name, :email
+ attr_accessor :name, :email, :token
validates :name, :presence => true
validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i
+ validates! :token, :presence => true
end
-person = Person.new
+person = Person.new(:token => "2b1f325")
person.valid? #=> false
person.name = 'vishnu'
person.email = 'me'
person.valid? #=> false
person.email = 'me@vishnuatrai.com'
person.valid? #=> true
+person.token = nil
+person.valid? #=> raises ActiveModel::StrictValidationFailed
h3. Changelog
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index aba3224ba7..18fc77c660 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -1270,6 +1270,7 @@ The +after_commit+ and +after_rollback+ callbacks are guaranteed to be called fo
h3. Changelog
+* August 24, 2011: Add strict validation usage example. "Bogdan Gusiev":http://gusiev.com
* February 17, 2011: Add description of transaction callbacks.
* July 20, 2010: Fixed typos and rephrased some paragraphs for clarity. "Jaime Iniesta":http://jaimeiniesta.com
* May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
--
cgit v1.2.3
From 0a2b105621383eafe09ed89ea7564da1c84057b1 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Wed, 24 Aug 2011 14:45:42 -0700
Subject: the command line guide is good to go
---
railties/guides/source/index.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index b48488d8a2..684251962c 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -124,7 +124,7 @@ Ruby on Rails Guides
This guide covers the basic configuration settings for a Rails application.
<% end %>
-<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html', :work_in_progress => true) do %>
+<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html') do %>
This guide covers the command line tools and rake tasks provided by Rails.
<% end %>
--
cgit v1.2.3
From 3731a0f97ba37224984ec81aaf56b6b1013a85e1 Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Wed, 24 Aug 2011 21:42:19 -0500
Subject: Update Debugging Assets section of Assets Pipeline guide
---
railties/guides/source/asset_pipeline.textile | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 012149c40e..4fbdda4c07 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -247,7 +247,14 @@ When the +debug_assets+ parameter is set, this line is expanded out into three s
This allows the individual parts of an asset to be rendered and debugged separately.
-NOTE. Assets debugging is turned on by default in development and test environments.
+Additionally if the +config.assets.debug+ is set to true you can debug your assets passing the +:debug+ option to the assets tags:
+
+
+<%= javascript_include_tag :application, :debug => true %>
+
+
+
+NOTE. Assets debugging is turned on by default in development and test environments. You can set +config.assets.allow_debugging+ to false to turn it off.
h3. In Production
--
cgit v1.2.3
From f2f05da06e48b5b4996380af33b59733048032f2 Mon Sep 17 00:00:00 2001
From: Bogdan Gusiev
Date: Thu, 25 Aug 2011 19:37:11 +0300
Subject: Moved strict validation changelog entry to right place
---
railties/guides/source/active_model_basics.textile | 1 +
railties/guides/source/active_record_validations_callbacks.textile | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index ec27a071c9..0672669dc5 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -204,4 +204,5 @@ person.valid? #=> raises ActiveModel::StrictValidationFai
h3. Changelog
+* August 24, 2011: Add strict validation usage example. "Bogdan Gusiev":http://gusiev.com
* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 18fc77c660..aba3224ba7 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -1270,7 +1270,6 @@ The +after_commit+ and +after_rollback+ callbacks are guaranteed to be called fo
h3. Changelog
-* August 24, 2011: Add strict validation usage example. "Bogdan Gusiev":http://gusiev.com
* February 17, 2011: Add description of transaction callbacks.
* July 20, 2010: Fixed typos and rephrased some paragraphs for clarity. "Jaime Iniesta":http://jaimeiniesta.com
* May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
--
cgit v1.2.3
From 8ba491acc31bf08cf63a83ea0a3c314c52cd020f Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Thu, 25 Aug 2011 18:51:17 +0100
Subject: Revert all the stuff to do with disallowing non-public methods for
Module#delegate
---
.../source/active_support_core_extensions.textile | 24 ----------------------
1 file changed, 24 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index df863935cf..b2436a2e68 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -452,30 +452,6 @@ Examples of +in?+:
NOTE: Defined in +active_support/core_ext/object/inclusion.rb+.
-h4. +public_send+
-
-This method is available by default in Ruby 1.9, and is backported to Ruby 1.8 by Active Support. Like the regular +send+ method, +public_send+ allows you to call a method when the name is not known until runtime. However, if the method is not public then a +NoMethodError+ exception will be raised.
-
-
-class Greeter
- def hello(who)
- "Hello " + who
- end
-
- private
-
- def secret
- "sauce"
- end
-end
-
-greeter = Greeter.new
-greeter.public_send(:hello, 'Jim') # => "Hello Jim"
-greeter.public_send(:secret) # => NoMethodError
-
-
-NOTE: Defined in +active_support/core_ext/object/public_send.rb+.
-
h3. Extensions to +Module+
h4. +alias_method_chain+
--
cgit v1.2.3
From b5f68cc6fe70490367c5c144e933a87feb5df966 Mon Sep 17 00:00:00 2001
From: Dimitar Dimitrov
Date: Fri, 26 Aug 2011 18:34:57 +0300
Subject: Fixed typos and made minor changes in the Plugins guide.
---
railties/guides/source/plugins.textile | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile
index d3f9783fa6..e8bdfa7f1c 100644
--- a/railties/guides/source/plugins.textile
+++ b/railties/guides/source/plugins.textile
@@ -290,7 +290,7 @@ You can then return to the root directory (+cd ../..+) of your plugin and rerun
-Getting closer...now we will implement the code of the acts_as_yaffle method to make the tests pass.
+Getting closer... Now we will implement the code of the acts_as_yaffle method to make the tests pass.
# yaffle/lib/yaffle/acts_as_yaffle.rb
@@ -322,7 +322,7 @@ When you run +rake+ you should see the tests all pass:
h4. Add an Instance Method
-This plugin will add a method named 'squawk' to any Active Record objects that call 'acts_as_yaffle'. The 'squawk'
+This plugin will add a method named 'squawk' to any Active Record object that calls 'acts_as_yaffle'. The 'squawk'
method will simply set the value of one of the fields in the database.
To start out, write a failing test that shows the behavior you'd like:
@@ -347,7 +347,7 @@ class ActsAsYaffleTest < Test::Unit::TestCase
assert_equal "squawk! Hello World", hickwall.last_squawk
end
- def test_wickwalls_squawk_should_populate_last_tweeted_at
+ def test_wickwalls_squawk_should_populate_last_tweet
wickwall = Wickwall.new
wickwall.squawk("Hello World")
assert_equal "squawk! Hello World", wickwall.last_tweet
@@ -355,7 +355,7 @@ class ActsAsYaffleTest < Test::Unit::TestCase
end
-Run the test to make sure the last two tests fail the an error that contains "NoMethodError: undefined method `squawk'",
+Run the test to make sure the last two tests fail with an error that contains "NoMethodError: undefined method `squawk'",
then update 'acts_as_yaffle.rb' to look like this:
@@ -400,11 +400,11 @@ the creation of generators can be found in the "Generators Guide":generators.htm
h3. Publishing your Gem
-Gem plugins in progress can be easily be shared from any Git repository. To share the Yaffle gem with others, simply
-commit the code to a Git repository (like Github) and add a line to the Gemfile of the any application:
+Gem plugins currently in development can easily be shared from any Git repository. To share the Yaffle gem with others, simply
+commit the code to a Git repository (like Github) and add a line to the Gemfile of the application in question:
-gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git'
+gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git'
After running +bundle install+, your gem functionality will be available to the application.
@@ -426,12 +426,12 @@ require 'yaffle'
You can test this by changing to the Rails application that you added the plugin to and starting a rails console. Once in the
-console we can check to see if the String has an instance method of to_squawk.
+console we can check to see if the String has an instance method to_squawk:
$ cd my_app
$ rails console
-$ String.instance_methods.sort
+$ "Rails plugins are easy!".to_squawk
You can also remove the .gemspec, Gemfile and Gemfile.lock files as they will no longer be needed.
@@ -445,9 +445,9 @@ The first step is to update the README file with detailed information about how
* Your name
* How to install
* How to add the functionality to the app (several examples of common use cases)
-* Warning, gotchas or tips that might help save users time
+* Warnings, gotchas or tips that might help users and save them time
-Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not part of the public api.
+Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not included in the public api.
Once your comments are good to go, navigate to your plugin directory and run:
--
cgit v1.2.3
From 871696a01af853f10a33c4ff53f6d6ed795144b7 Mon Sep 17 00:00:00 2001
From: Igor Zubkov
Date: Sun, 28 Aug 2011 23:08:06 +0300
Subject: Documentation fixes
---
railties/guides/source/asset_pipeline.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 4fbdda4c07..554246acb3 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -29,7 +29,7 @@ It is recommended that you use the defaults for all new apps.
h4. Main Features
-The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assetsi -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it.
+The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it.
The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production, an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered.
@@ -133,7 +133,7 @@ Otherwise, Sprockets looks through the available paths until it finds a file tha
If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper.
-#logo { background: url(<%= asset_data_uri 'logo.png' %>)
+#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
This inserts a correctly-formatted data URI into the CSS source.
@@ -143,7 +143,7 @@ h5. CSS and ERB
If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules:
-.class{background-image:<%= asset_path 'image.png' %>}
+.class { background-image: <%= asset_path 'image.png' %> }
This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced.
@@ -282,7 +282,7 @@ Rails comes bundled with a rake task to compile the manifests to files on disc.
The rake task is:
-rake assets:precompile
+bundle exec rake assets:precompile
Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the following line to +Capfile+:
--
cgit v1.2.3
From 2350fecd2251584d770afc4bd1764b3fe526ff70 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Tue, 30 Aug 2011 13:48:16 -0700
Subject: adds the asset pipeline guide to the index
---
railties/guides/source/asset_pipeline.textile | 2 +-
railties/guides/source/index.html.erb | 4 ++++
railties/guides/source/layout.html.erb | 3 ++-
3 files changed, 7 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 554246acb3..2695ba9ec1 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -1,6 +1,6 @@
h2. Asset Pipeline
-This guide covers the ideology of the asset pipeline introduced in Rails 3.1.
+This guide covers the asset pipeline introduced in Rails 3.1.
By referring to this guide you will be able to:
* Understand what the asset pipeline is and what it does
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index 684251962c..b7813086d7 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -131,6 +131,10 @@ Ruby on Rails Guides
<%= guide("Caching with Rails", 'caching_with_rails.html', :work_in_progress => true) do %>
Various caching techniques provided by Rails.
<% end %>
+
+<%= guide('Asset Pipeline', 'asset_pipeline.html') do %>
+
--
cgit v1.2.3
From 84dad446c6a23a15f67b9d558e8039891a008bff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Mej=C3=ADa?=
Date: Sat, 27 Aug 2011 23:10:25 -0500
Subject: Adding first_or_create, first_or_create!, first_or_new and
first_or_build to Active Record.
This let's you write things like:
User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson", :hot => true)
Related to #2420.
---
.../guides/source/active_record_querying.textile | 75 ++++++++++++++++++++--
1 file changed, 68 insertions(+), 7 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 4e77a6e803..37874c2ea1 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1018,23 +1018,84 @@ If you want to find both by name and locked, you can chain these finders togethe
WARNING: Up to and including Rails 3.1, when the number of arguments passed to a dynamic finder method is lesser than the number of fields, say Client.find_by_name_and_locked("Ryan"), the behavior is to pass +nil+ as the missing argument. This is *unintentional* and this behavior will be changed in Rails 3.2 to throw an +ArgumentError+.
-There's another set of dynamic finders that let you find or create/initialize objects if they aren't found. These work in a similar fashion to the other finders and can be used like +find_or_create_by_first_name(params[:first_name])+. Using this will first perform a find and then create if the find returns +nil+. The SQL looks like this for +Client.find_or_create_by_first_name("Ryan")+:
+h3. Find or build a new object
+
+It's common that you need to find a record or create it if it doesn't exist. You can do that with the +first_or_create+ and +first_or_create!+ methods.
+
+h4. +first_or_create+
+
+The +first_or_create+ method checks whether +first+ returns +nil+ or not. If it does return +nil+, then +create+ is called. This is very powerful when coupled with the +where+ method. Let's see an example.
+
+Suppose you want to find a client named 'Andy', and if there's none, create one and additionally set his +locked+ attribute to false. You can do so by running:
+
+
+Client.where(:first_name => 'Andy').first_or_create(:locked => false)
+# =>
+
+
+The SQL generated by this method looks like this:
-SELECT * FROM clients WHERE (clients.first_name = 'Ryan') LIMIT 1
+SELECT * FROM clients WHERE (clients.first_name = 'Andy') LIMIT 1
BEGIN
-INSERT INTO clients (first_name, updated_at, created_at, orders_count, locked)
- VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', 0, '0')
+INSERT INTO clients (created_at, first_name, locked, orders_count, updated_at) VALUES ('2011-08-30 05:22:57', 'Andy', 0, NULL, '2011-08-30 05:22:57')
COMMIT
-+find_or_create+'s sibling, +find_or_initialize+, will find an object and if it does not exist will act similarly to calling +new+ with the arguments you passed in. For example:
++first_or_create+ returns either the record that already existed or the new record. In our case, we didn't already have a client named Andy so the record was created an returned.
+
+The new record might not be saved to the database; that depends on whether validations passed or not (just like +create+).
+
+It's also worth noting that +first_or_create+ takes into account the arguments of the +where+ method. In the example above we didn't explicitly pass a +:first_name => 'Andy'+ argument to +first_or_create+. However, that was used when creating the new record because it was already passed before to the +where+ method.
+
+NOTE: On previous versions of Rails you could do a similar thing with the +find_or_create_by+ method. Following our example, you could also run something like +Client.find_or_create_by_first_name(:first_name => "Andy", :locked => false)+. This method still works, but it's encouraged to use +first_or_create+ because it's more explicit on what arguments are used to _find_ the record and what arguments are used to _create_ it, resulting in less confusion overall.
+
+h4. +first_or_create!+
+
+You can also use +first_or_create!+ to raise an exception if the new record is invalid. Validations are not covered on this guide, but let's assume for a moment that you temporarily add
+
+
+ validates :orders_count, :presence => true
+
+
+to your +Client+ model. If you try to create a new +Client+ without passing an +orders_count+, the record will be invalid and an exception will be raised:
+
+
+Client.where(:first_name => 'Andy').first_or_create!(:locked => false)
+# => ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank
+
+
+NOTE: Be sure to check the extensive *Active Record Validations and Callbacks Guide* for more information about validations.
+
+h4. +first_or_new+
+
+The +first_or_new+ method will work just like +first_or_create+ but it will not call +create+ but the +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick':
+
+
+nick = Client.where(:first_name => 'Nick').first_or_new(:locked => false)
+# =>
+
+nick.persisted?
+# => false
+
+nick.new_record?
+# => true
+
+
+Because the object is not yet stored in the database, the SQL generated looks like this:
+
+
+SELECT * FROM clients WHERE (clients.first_name = 'Nick') LIMIT 1
+
+
+When you want to save it to the database, just call +save+:
-client = Client.find_or_initialize_by_first_name('Ryan')
+nick.save
+# => true
-will either assign an existing client object with the name "Ryan" to the client local variable, or initialize a new object similar to calling +Client.new(:first_name => 'Ryan')+. From here, you can modify other fields in client by calling the attribute setters on it: +client.locked = true+ and when you want to write it to the database just call +save+ on it.
+Just like you can use *+build+* instead of *+new+*, you can use *+first_or_build+* instead of *+first_or_new+*.
h3. Finding by SQL
--
cgit v1.2.3
From ee822f257e2f3f3b571772f30ae3a8edd69538c3 Mon Sep 17 00:00:00 2001
From: Nicolas Hock Isaza
Date: Tue, 30 Aug 2011 15:40:09 -0500
Subject: Adding `first_or_new` documentation to the AR Querying guide.
---
railties/guides/source/active_record_querying.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 37874c2ea1..54ce7a25ab 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1069,7 +1069,7 @@ NOTE: Be sure to check the extensive *Active Record Validations and Callbacks Gu
h4. +first_or_new+
-The +first_or_new+ method will work just like +first_or_create+ but it will not call +create+ but the +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick':
+The +first_or_new+ method will work just like +first_or_create+ but it will not call +create+ but +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick':
nick = Client.where(:first_name => 'Nick').first_or_new(:locked => false)
--
cgit v1.2.3
From 331dad14bc0623a8b1f24be88f2933c20c346c74 Mon Sep 17 00:00:00 2001
From: Ray Baxter
Date: Tue, 30 Aug 2011 22:32:09 -0700
Subject: don't need edgeapi now that we are on 3.1
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 087926f98d..156987efc4 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -170,7 +170,7 @@ class PostsController < ActionController::Base
end
-You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
+You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "ActionController::Streaming":http://api.rubyonrails.org/classes/ActionController/Streaming.html for more information.
* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused.
--
cgit v1.2.3
From 73263f6c81936b199f7410991a23ea380a58e005 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Wed, 31 Aug 2011 01:44:59 -0700
Subject: adds the release notes of 3.1 to the index
---
railties/guides/source/index.html.erb | 4 ++++
railties/guides/source/layout.html.erb | 1 +
2 files changed, 5 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index b7813086d7..214155c088 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -174,6 +174,10 @@ Ruby on Rails Guides
Release Notes
+<%= guide("Ruby on Rails 3.1 Release Notes", '3_1_release_notes.html') do %>
+
Release notes for Rails 3.1.
+<% end %>
+
<%= guide("Ruby on Rails 3.0 Release Notes", '3_0_release_notes.html') do %>
Release notes for Rails 3.0.
<% end %>
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index 5f8ee57517..3ccbc3a477 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -84,6 +84,7 @@
--
cgit v1.2.3
From d7be97ec31f5d972e01fb11b05ca4b36f581c779 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Wed, 31 Aug 2011 01:52:43 -0700
Subject: release notes: adds a couple of blank lines to get the markup right
---
railties/guides/source/3_1_release_notes.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 087926f98d..9ca77d0657 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -346,6 +346,7 @@ has_many :things, :conditions => proc { "foo = #{bar}" } # after
Inside the proc, +self+ is the object which is the owner of the association, unless you are eager loading the association, in which case +self+ is the class which the association is within.
You can have any "normal" conditions inside the proc, so the following will work too:
+
has_many :things, :conditions => proc { ["foo = ?", bar] }
@@ -353,6 +354,7 @@ has_many :things, :conditions => proc { ["foo = ?", bar] }
* Previously +:insert_sql+ and +:delete_sql+ on +has_and_belongs_to_many+ association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc.
* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting.
+
# Schema: User(name:string, password_digest:string, password_salt:string)
class User < ActiveRecord::Base
--
cgit v1.2.3
From e746c4047cd34accd7f63aa5d09cbb35011c24e2 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Wed, 31 Aug 2011 02:04:36 -0700
Subject: syncs assets guide with what's in 3-1-stable
---
railties/guides/source/asset_pipeline.textile | 38 +++++++++++++++++++--------
1 file changed, 27 insertions(+), 11 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 2695ba9ec1..96b11dbf63 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -15,7 +15,7 @@ h3. What is the Asset Pipeline?
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB.
-Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 includes the +sprockets-rails+ gem, which depends on the +sprockets+ gem, by default.
+Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets throught ActionPack which depends on the +sprockets+ gem, by default.
By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf.
@@ -27,6 +27,7 @@ config.assets.enabled = false
It is recommended that you use the defaults for all new apps.
+
h4. Main Features
The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it.
@@ -74,11 +75,14 @@ The other problem is that when static assets are deployed with each new release
Fingerprinting avoids all these problems by ensuring filenames are consistent based on their content.
+Fingerprinting is enabled by default for production and disabled for all the others environments. You can enable or disable it in your configuration through the +config.assets.digest+ option.
+
More reading:
* "Optimize caching":http://code.google.com/speed/page-speed/docs/caching.html
* "Revving Filenames: don’t use querystring":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
+
h3. How to Use the Asset Pipeline
In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory are served by the Sprockets middleware included in the sprockets gem.
@@ -247,14 +251,7 @@ When the +debug_assets+ parameter is set, this line is expanded out into three s
This allows the individual parts of an asset to be rendered and debugged separately.
-Additionally if the +config.assets.debug+ is set to true you can debug your assets passing the +:debug+ option to the assets tags:
-
-
-<%= javascript_include_tag :application, :debug => true %>
-
-
-
-NOTE. Assets debugging is turned on by default in development and test environments. You can set +config.assets.allow_debugging+ to false to turn it off.
+NOTE. Assets debugging is turned on by default in development and test environments.
h3. In Production
@@ -271,7 +268,7 @@ The MD5 is generated from the contents of the compiled files, and is included in
Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache.
-This behavior is controlled by the setting of +config.action_controller.perform_caching+ setting in Rails (which is +true+ for production, +false+ for everything else). This value is propagated to Sprockets during initialization for use when action_controller is not available.
+This behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else).
h4. Precompiling Assets
@@ -307,6 +304,20 @@ If you have other manifests or individual stylesheets and JavaScript files to in
config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
+The rake task also generates a +manifest.yml+ that contains a list with all your assets and their fingerprints, using this manifest file the assets helpers avoid hitting to Sprockets to recalculate MD5 hashes for files. Manifest file typically look like this:
+
+
+---
+rails.png: rails-bd9ad5a560b5a3a7be0808c5cd76a798.png
+jquery-ui.min.js: jquery-ui-7e33882a28fc84ad0e0e47e46cbf901c.min.js
+jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js
+application.js: application-3fdab497b8fb70d20cfc5495239dfc29.js
+application.css: application-8af74128f904600e41a6e39241464e03.css
+
+
+The manifest file is generated by default in same folder of your precompiled assets, you can change the location of the file setting the +config.assets.manifest+ option with the full path of the folder where you want save it.
+
+
Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them.
For Apache:
@@ -325,12 +336,16 @@ For Apache:
-TODO: NGINX instructions
+TODO: nginx instructions
When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used:
TODO: Apache instructions
+TODO: nginx instructions
+
+By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the +config.assets.compile+ to true. You can use this option to fallback to Sprockets when you are using precompiled assets but there are any missing precompiled files. If +config.assets.compile+ option is set to false and there are missing precompiled files you will get an "AssetNoPrecompiledError" indicating the name of the missing file.
+
h3. Customizing the Pipeline
@@ -378,6 +393,7 @@ To enable this, pass a +new+ Object to the config option in +application.rb+:
config.assets.css_compressor = Transformer.new
+
h4. Changing the _assets_ Path
The public path that Sprockets uses by default is +/assets+.
--
cgit v1.2.3
From 6d772c0953b418da774b2c3bf5cc297508669da7 Mon Sep 17 00:00:00 2001
From: Semyon Perepelitsa
Date: Wed, 31 Aug 2011 14:40:45 +0400
Subject: Fix typo: => instead of =
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index ba36735a0b..b9850daf15 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -245,7 +245,7 @@ class User < ActiveRecord::Base
has_one :account
end
-user.build_account{ |a| a.credit_limit => 100.0 }
+user.build_account{ |a| a.credit_limit = 100.0 }
* Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist.
--
cgit v1.2.3
From 30d65da17e5fb1cdd3f10a6d14f4295b57e26286 Mon Sep 17 00:00:00 2001
From: Rodrigo Rosenfeld Rosas
Date: Wed, 31 Aug 2011 10:50:08 -0300
Subject: Fix logic in 3.1 release notes sentence
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 4412d32cce..7de8866ff6 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -271,7 +271,7 @@ Post.new(params[:post], :as => :admin)
* +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed.
-* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
+* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is not recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
* Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations.
--
cgit v1.2.3
From 120b534d8e66a4b00764df3c08ff369c91756754 Mon Sep 17 00:00:00 2001
From: Andrew Olson
Date: Wed, 31 Aug 2011 14:18:01 -0400
Subject: Fixing spelling, throught -> through.
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 96b11dbf63..76c8f520e5 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -15,7 +15,7 @@ h3. What is the Asset Pipeline?
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB.
-Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets throught ActionPack which depends on the +sprockets+ gem, by default.
+Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through ActionPack which depends on the +sprockets+ gem, by default.
By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf.
--
cgit v1.2.3
From 054bdc1f59a035e1b50febac1487f9b982d6e63a Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Thu, 1 Sep 2011 09:11:00 +1200
Subject: Add section to pipeline docs to help people upgrading
These are the options from a brand new app, and
should help people get it right when upgrading.
---
railties/guides/source/asset_pipeline.textile | 47 +++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 76c8f520e5..222ee44de0 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -434,3 +434,50 @@ A good example of this is the +jquery-rails+ gem which comes with Rails as the s
h3. Making Your Library or Gem a Pre-Processor
TODO: Registering gems on "Tilt":https://github.com/rtomayko/tilt enabling Sprockets to find them.
+
+h3. Upgrading from Old Versions of Rails
+
+There are two issues when upgrading. The first is moving the files to the new locations. See the section above for guidance on the correct locations for different file types.
+
+The second is updating the various environment files with the correct default options. The following changes reflect the defaults in version 3.1.0.
+
+In +application.rb+:
+
+
+# Enable the asset pipeline
+config.assets.enabled = true
+
+# Version of your assets, change this if you want to expire all your assets
+config.assets.version = '1.0'
+
+
+In +development.rb+:
+
+
+# Do not compress assets
+config.assets.compress = false
+
+# Expands the lines which load the assets
+config.assets.debug = true
+
+
+And in +production.rb+:
+
+
+# Compress JavaScripts and CSS
+config.assets.compress = true
+
+# Don't fallback to assets pipeline if a precompiled asset is missed
+config.assets.compile = false
+
+# Generate digests for assets URLs
+config.assets.digest = true
+
+# Defaults to Rails.root.join("public/assets")
+# config.assets.manifest = YOUR_PATH
+
+# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+# config.assets.precompile += %w( search.js )
+
+
+There are no changes to +test.rb+.
--
cgit v1.2.3
From 2422fbf6287f7d97859bc50ec1417b95b0b703d5 Mon Sep 17 00:00:00 2001
From: Ray Baxter
Date: Wed, 31 Aug 2011 15:19:06 -0700
Subject: make code example agree with text just above
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index d2bfcfdbb4..256df0eded 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1604,7 +1604,7 @@ action, except for +index+ and +show+, so we write that:
class PostsController < ApplicationController
- http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
+ http_basic_authenticate_with :name => "dhh", :password => "secret", :except => [:index, :show]
# GET /posts
# GET /posts.json
--
cgit v1.2.3
From 5767c13c6809e0171614dd54a812fd1d6f5ae471 Mon Sep 17 00:00:00 2001
From: Greg Leppert
Date: Wed, 31 Aug 2011 19:39:41 -0300
Subject: Update wording surrounding template file extensions to include Rails
3 and above.
---
railties/guides/source/layouts_and_rendering.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 87ba8ab82d..310a70ca9b 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -90,7 +90,7 @@ If we want to display the properties of all the books in our view, we can do so
<%= link_to 'New book', new_book_path %>
-NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. In Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), and +.builder+ for Builder (XML generator).
+NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. Beginning with Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), and +.builder+ for Builder (XML generator).
h4. Using +render+
--
cgit v1.2.3
From f0af56395288d6081d5b36f599fa6bc8695463d6 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Thu, 1 Sep 2011 10:52:59 +1200
Subject: Added new asset config options to guides
---
railties/guides/source/configuring.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 110c04f66e..798f8e405e 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -134,6 +134,18 @@ Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets wit
* +config.assets.prefix+ defines the prefix where assets are served from. Defaults to +/assets+.
+* +config.assets.digest+ enables the use of MD5 fingerprints in asset names. Set to +true+ by default in +production.rb+
+
+* +config.assets.debug+ disables the concatenation and compression of assets. Set to +false+ by default in +development.rb+
+
+* +config.assets.manifest+ defines the full path to be used for the asset precompiler's manifest file. Defaults to using +config.assets.prefix+
+
+* +config.assets.cache_store+ defines the cache store that Sprockets will use. The default is the Rails file store.
+
+* +config.assets.version+ is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.
+
+* +config.assets.compile+ is a boolean that can be used to turn on live Sprockets compilation in production.
+
h4. Configuring Generators
--
cgit v1.2.3
From 6ce6ba8638f4995e8e7d57b304fc31d6e27ae0e5 Mon Sep 17 00:00:00 2001
From: Kir
Date: Thu, 1 Sep 2011 02:37:54 +0400
Subject: Instructions for nginx and apache added
---
railties/guides/source/asset_pipeline.textile | 30 +++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 222ee44de0..d621dd5a70 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -340,9 +340,35 @@ TODO: nginx instructions
When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used:
-TODO: Apache instructions
+For Apache:
-TODO: nginx instructions
+
+
+ # 2 lines to serve pre-gzipped version
+ RewriteCond %{REQUEST_FILENAME}.gz -s
+ RewriteRule ^(.+) $1.gz [L]
+
+ # without it, Content-Type will be "application/x-gzip"
+
+ ForceType text/css
+
+
+
+ ForceType text/javascript
+
+
+
+
+For nginx:
+
+
+location ~ ^/(assets)/ {
+ root /path/to/public;
+ gzip_static on; # to serve pre-gzipped version
+ expires max;
+ add_header Cache-Control public;
+}
+
By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the +config.assets.compile+ to true. You can use this option to fallback to Sprockets when you are using precompiled assets but there are any missing precompiled files. If +config.assets.compile+ option is set to false and there are missing precompiled files you will get an "AssetNoPrecompiledError" indicating the name of the missing file.
--
cgit v1.2.3
From fe07669e276520c1da42153a9a2bfe7991bfd6d1 Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Wed, 31 Aug 2011 20:05:59 -0500
Subject: Review config.assets options.
---
railties/guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 798f8e405e..050fcd823d 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -124,7 +124,7 @@ Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets wit
* +config.assets.compress+ a flag that enables the compression of compiled assets. It is explicitly set to true in +config/production.rb+.
-* +config.assets.css_compressor+ defines the CSS compressor to use. Only supported value at the moment is +:yui+, which uses the +yui-compressor+ gem.
+* +config.assets.css_compressor+ defines the CSS compressor to use. It is set by default by +sass-rails+. The unique alternative value at the moment is +:yui+, which uses the +yui-compressor+ gem.
* +config.assets.js_compressor+ defines the JavaScript compressor to use. Possible values are +:closure+, +:uglifier+ and +:yui+ which require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively.
--
cgit v1.2.3
From ed1dfaf48da81fa5d88248950419b3a552b44ecf Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Thu, 1 Sep 2011 13:28:33 +1200
Subject: update pipeline docs to reflect new defaults
Production section has been changed to reflect the
new default of precompilation and using the asset
manifest.
Development has been swapped around to reflect the
new default (debug mode is on).
Other changes to support this elsewhere.
---
railties/guides/source/asset_pipeline.textile | 125 +++++++++++++++++++-------
1 file changed, 93 insertions(+), 32 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index d621dd5a70..f62b7e5c65 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -222,59 +222,76 @@ Keep in mind that the order of these pre-processors is important. For example, i
h3. In Development
-In the development environment assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response.
+In development mode assets are served as separate files in the order they are specified in the manifest file.
-If any of the files in the manifest have changed between requests, the server responds with a new compiled file.
-
-h4. Debugging Assets
-
-You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL or set +config.assets.debug+ and Sprockets expands the lines which load the assets. For example, if you had an +app/assets/javascripts/application.js+ file containing these lines:
+This manifest +application.js+:
-//= require "projects"
-//= require "tickets"
+//= require core
+//= require projects
+//= require tickets
-By default, this only renders this line when used with +<%= javascript_include_tag "application" %>+ in a view or layout:
+would generate this HTML:
-
+
+
+
-When the +debug_assets+ parameter is set, this line is expanded out into three separate lines, separating out the combined file into their parts.
+h4. Turning Debugging off
+
+You can turn off debug mode by updating +development.rb+ to include:
+
+
+config.assets.debug = false
+
+
+When debug mode is off Sprockets will concatenate and run the necessary preprocessors on all files, generating the following HTML:
-
-
-This allows the individual parts of an asset to be rendered and debugged separately.
+Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response.
+
+If any of the files in the manifest have changed between requests, the server responds with a new compiled file.
+
+You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render indivudual tags for each file. This is useful for tracking down exact line numbers when debugging.
+
+You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging.
-NOTE. Assets debugging is turned on by default in development and test environments.
h3. In Production
-In the production environment, assets are served slightly differently.
+In the production environment Rails uses the fingerprinting scheme outlined above. By default it is assumed that assets have been precompiled and will be served as static assets by your web server.
-On the first request the assets are compiled and cached as described above, however the manifest names are altered to include an MD5 hash. Files names typically look like these:
+During the precompilation phase an MD5 is generated from the contents of the compiled files, and inserted into the filenames as they are written to disc. These fingerprinted names are used by the Rails helpers in place of the manifest name.
-
-/assets/application-908e25f4bf641868d8683022a5b62f54.js
-/assets/application-4dd5b109ee3439da54f5bdfd78a80473.css
-
+For example this:
-The MD5 is generated from the contents of the compiled files, and is included in the HTTP +Content-MD5+ header.
+
+<%= javascript_include_tag "application" %>
+<%= stylesheet_link_tag "application" %>
+
-Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache.
+generates something like this:
+
+
+
+
+
-This behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else).
+The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). under normal circumstances the default options should not be changed.
h4. Precompiling Assets
-Even though assets are served by Rack::Cache with far-future headers, in high traffic sites this may not be fast enough.
+Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to disc.
-Rails comes bundled with a rake task to compile the manifests to files on disc. These are located in the +public/assets+ directory where they are served by your web server instead of the Rails application.
+Compiled assets are written to the location specified in +config.assets.prefix+. The default setting will use the +public/assets+ directory.
+
+You must use this task either during deployment or locally if you do not have write access to your production filesystem.
The rake task is:
@@ -288,7 +305,7 @@ Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the followin
load 'deploy/assets'
-This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this folder you'll need to write your own deployment task.
+This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this shared folder you'll need to write your own deployment task.
It is important that this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page.
@@ -298,13 +315,13 @@ The default matcher for compiling files includes +application.js+, +application.
[ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
-If you have other manifests or individual stylesheets and JavaScript files to include, you can append them to the +precompile+ array:
+If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the +precompile+ array:
config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
-The rake task also generates a +manifest.yml+ that contains a list with all your assets and their fingerprints, using this manifest file the assets helpers avoid hitting to Sprockets to recalculate MD5 hashes for files. Manifest file typically look like this:
+The rake task also generates a +manifest.yml+ that contains a list with all your assets and their respective fingerprints. This is used by the Rails helper methods and avoids handing the mapping requests back to Sprockets. Manifest file typically look like this:
---
@@ -315,8 +332,17 @@ application.js: application-3fdab497b8fb70d20cfc5495239dfc29.js
application.css: application-8af74128f904600e41a6e39241464e03.css
-The manifest file is generated by default in same folder of your precompiled assets, you can change the location of the file setting the +config.assets.manifest+ option with the full path of the folder where you want save it.
+The default location for the manifest is the root of the location specified in +config.assets.prefix+ ('/assets' by default).
+
+This can be changed with the +config.assets.manifest+ option. A fully specified path is required:
+
+config.assets.manifest = '/path/to/some/other/location'
+
+
+NOTE: If there are missing precompiled files in production you will get an "AssetNoPrecompiledError" exception indicating the name of the missing file.
+
+h5. Server Configuration
Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them.
@@ -370,10 +396,23 @@ location ~ ^/(assets)/ {
}
-By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the +config.assets.compile+ to true. You can use this option to fallback to Sprockets when you are using precompiled assets but there are any missing precompiled files. If +config.assets.compile+ option is set to false and there are missing precompiled files you will get an "AssetNoPrecompiledError" indicating the name of the missing file.
+h4. Live Compilation
-h3. Customizing the Pipeline
+In some circumstances you may wish to use live compilation. In this mode all requests for assets in the Pipeline are handled by Sprockets directly.
+
+To enable this options set:
+
+
+config.assets.compile = true
+
+
+On the first request the assets are compiled and cached as outlined in development above, and the manifest names used in the helpers are altered to include the MD5 hash.
+
+Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache.
+
+This mode uses more memory and is lower performance than the default. It is not recommended.
+h3. Customizing the Pipeline
h4. CSS Compression
@@ -475,6 +514,10 @@ config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
+
+# Change the path that assets are served from
+# config.assets.prefix = "/assets"
+
In +development.rb+:
@@ -493,6 +536,11 @@ And in +production.rb+:
# Compress JavaScripts and CSS
config.assets.compress = true
+# Choose the compressors to use
+# config.assets.js_compressor = :uglifier
+# config.assets.css_compressor = :yui
+
+
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
@@ -507,3 +555,16 @@ config.assets.digest = true
There are no changes to +test.rb+.
+
+The following should also be added to +Gemfile+:
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', " ~> 3.1.0"
+ gem 'coffee-rails', "~> 3.1.0"
+ gem 'uglifier'
+end
+
+
--
cgit v1.2.3
From 4ba35dd26b8f02ab851e9d8431a1fe78264e2d51 Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Thu, 1 Sep 2011 00:35:01 -0500
Subject: Giving info about what are the defaults for test environment
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index f62b7e5c65..8bcddfbb4b 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -554,7 +554,7 @@ config.assets.digest = true
# config.assets.precompile += %w( search.js )
-There are no changes to +test.rb+.
+There are no changes to +test.rb+. For test environment by default +config.assets.compile+ is true and +config.assets.compress+, +config.assets.debug+ and +config.assets.digest+ are false
The following should also be added to +Gemfile+:
--
cgit v1.2.3
From 418e321b506645bc0fb69116f01de41546a8cacf Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Thu, 1 Sep 2011 01:01:31 -0500
Subject: Fixing sass-rails helpers methods examples
---
railties/guides/source/asset_pipeline.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 8bcddfbb4b..9ff4f0d062 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -158,13 +158,13 @@ h5. CSS and SCSS
When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, javascript, stylesheet.
-* +image_url("rails.png")+ becomes +url(/assets/rails.png)+
-* +image_path("rails.png")+ becomes +"/assets/rails.png"+.
+* +image-url("rails.png")+ becomes +url(/assets/rails.png)+
+* +image-path("rails.png")+ becomes +"/assets/rails.png"+.
The more generic form can also be used but the asset path and class must both be specified:
-* +asset_url("rails.png", "image")+ becomes +url(/assets/rails.png)+
-* +asset_path("rails.png", "image")+ becomes +"/assets/rails.png"+
+* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+
+* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+
h4. Manifest Files and Directives
--
cgit v1.2.3
From fdf2f519bd948003b851a1eff8a6f157297a46ad Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Thu, 1 Sep 2011 01:15:19 -0500
Subject: Add reference to ExecJS in JavaScript Compression section
---
railties/guides/source/asset_pipeline.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 9ff4f0d062..b06abc82cf 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -426,7 +426,7 @@ config.assets.css_compressor = :yui
The +config.assets.compress+ must be set to +true+ to enable CSS compression
-h4. JavaScript
+h4. JavaScript Compression
Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively.
@@ -440,6 +440,8 @@ config.assets.js_compressor = :uglifier
The +config.assets.compress+ must be set to +true+ to enable JavaScript compression
+NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have a JavaScript engine in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
+
h4. Using Your Own Compressor
The compressor config settings for CSS and JavaScript also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string.
--
cgit v1.2.3
From 72fea6d2ebd9a40d78f0d6ad0fdbdf80298458e9 Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Thu, 1 Sep 2011 01:18:20 -0500
Subject: Adding reference about ExecJS for CoffeeScript
---
railties/guides/source/asset_pipeline.textile | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index b06abc82cf..e428684079 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -89,10 +89,12 @@ In previous versions of Rails, all assets were located in subdirectories of +pub
This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served.
-When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-script+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller.
+When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller.
For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
+NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
+
h4. Asset Organization
Assets can be placed inside an application in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+.
@@ -440,7 +442,7 @@ config.assets.js_compressor = :uglifier
The +config.assets.compress+ must be set to +true+ to enable JavaScript compression
-NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have a JavaScript engine in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
+NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
h4. Using Your Own Compressor
--
cgit v1.2.3
From 5421d4d0161949e24f63bab30b82be694761a6d4 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Thu, 1 Sep 2011 18:25:24 +1200
Subject: pipeline docs - spelling and some whitespace
---
railties/guides/source/asset_pipeline.textile | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index e428684079..a0e51aa57c 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -282,7 +282,7 @@ generates something like this:
-
+
The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). under normal circumstances the default options should not be changed.
@@ -375,7 +375,7 @@ For Apache:
# 2 lines to serve pre-gzipped version
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
-
+
# without it, Content-Type will be "application/x-gzip"
ForceType text/css
@@ -402,7 +402,7 @@ h4. Live Compilation
In some circumstances you may wish to use live compilation. In this mode all requests for assets in the Pipeline are handled by Sprockets directly.
-To enable this options set:
+To enable this option set:
config.assets.compile = true
@@ -442,7 +442,7 @@ config.assets.js_compressor = :uglifier
The +config.assets.compress+ must be set to +true+ to enable JavaScript compression
-NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
+NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
h4. Using Your Own Compressor
@@ -506,7 +506,7 @@ TODO: Registering gems on "Tilt":https://github.com/rtomayko/tilt enabling Sproc
h3. Upgrading from Old Versions of Rails
-There are two issues when upgrading. The first is moving the files to the new locations. See the section above for guidance on the correct locations for different file types.
+There are two issues when upgrading. The first is moving the files to the new locations. See the section above for guidance on the correct locations for different file types.
The second is updating the various environment files with the correct default options. The following changes reflect the defaults in version 3.1.0.
--
cgit v1.2.3
From 1f998c7578d343310a4309bc0b06af224132648d Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Thu, 1 Sep 2011 21:15:06 +1200
Subject: pipeline docs improvement
Some cleaning up of whitespace/punctuation
and text refinements to clarify some things.
---
railties/guides/source/asset_pipeline.textile | 45 +++++++++++++++------------
1 file changed, 25 insertions(+), 20 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index a0e51aa57c..3ed75a28ef 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -105,13 +105,17 @@ Assets can be placed inside an application in one of three locations: +app/asset
+vendor/assets+ is for assets that are owned by outside entities, such as code for JavaScript plugins.
-All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served.
+All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are traversed to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served.
-h4. Coding Links to Assets
+You can add additional (fully qualified) paths to the pipeline in +application.rb+. For example:
+
+
+config.assets.paths << File.join(Rails.root, 'app', 'assets', 'flash')
+
-To access assets, you use the same tags that you are generally familiar with:
+h4. Coding Links to Assets
-Sprockets does not add any new methods to require your assets, you still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+.
+Sprockets does not add any new methods to access your assets - you still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+.
<%= stylesheet_link_tag "application" %>
@@ -124,17 +128,17 @@ In regular views you can access images in the +assets/images+ directory like thi
<%= image_tag "rails.png" %>
-Images can be organized into directories if required, and they can be accessed by specifying the directory's name in the tag:
+Provided that the pipeline is enabled within your application (and not disabled in the current environment context), this file is served by Sprockets. If a file exists at +public/assets/rails.png+ it is served by the webserver.
-
-<%= image_tag "icons/rails.png" %>
-
+Alternatively, a request for a file with an MD5 hash such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is treated the same way. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide.
-Providing that assets are enabled within your application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file is served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file is served.
+Sprockets will also look through the paths specified in +config.assets.paths+ which includes the standard application paths and any path added by Rails engines.
-Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is also picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide.
+Images can also be organized into subdirectories if required, and they can be accessed by specifying the directory's name in the tag:
-Otherwise, Sprockets looks through the available paths until it finds a file that matches the name and then serves it, first looking in the application's assets directories and then falling back to the various engines of the application.
+
+<%= image_tag "icons/rails.png" %>
+
If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper.
@@ -256,7 +260,7 @@ When debug mode is off Sprockets will concatenate and run the necessary preproce
-Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response.
+Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response.
If any of the files in the manifest have changed between requests, the server responds with a new compiled file.
@@ -285,7 +289,9 @@ generates something like this:
-The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else). under normal circumstances the default options should not be changed.
+The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else).
+
+NOTE: Under normal circumstances the default options should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes.
h4. Precompiling Assets
@@ -366,7 +372,7 @@ For Apache:
TODO: nginx instructions
-When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the public/assets folder. The following configuration options can be used:
+When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used:
For Apache:
@@ -418,7 +424,7 @@ h3. Customizing the Pipeline
h4. CSS Compression
-There is currently one option for compressing CSS - YUI. This Gem extends the CSS syntax and offers minification.
+There is currently one option for compressing CSS, YUI. This Gem extends the CSS syntax and offers minification.
The following line enables YUI compression, and requires the +yui-compressor+ gem.
@@ -442,7 +448,7 @@ config.assets.js_compressor = :uglifier
The +config.assets.compress+ must be set to +true+ to enable JavaScript compression
-NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
+NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme -- supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
h4. Using Your Own Compressor
@@ -490,7 +496,7 @@ WARNING: If you are upgrading an existing application and intend to use this opt
h3. How Caching Works
-Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is file names are fingerprinted and get far-future headers in production.
+Sprockets uses the default rails cache store to cache assets in development and production.
TODO: Add more about changing the default store.
@@ -544,11 +550,10 @@ config.assets.compress = true
# config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :yui
-
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
-# Generate digests for assets URLs
+# Generate digests for assets URLs.
config.assets.digest = true
# Defaults to Rails.root.join("public/assets")
@@ -558,7 +563,7 @@ config.assets.digest = true
# config.assets.precompile += %w( search.js )
-There are no changes to +test.rb+. For test environment by default +config.assets.compile+ is true and +config.assets.compress+, +config.assets.debug+ and +config.assets.digest+ are false
+There are no changes to +test.rb+. The defaults in the test environment are: +config.assets.compile+ is true and +config.assets.compress+, +config.assets.debug+ and +config.assets.digest+ are false.
The following should also be added to +Gemfile+:
--
cgit v1.2.3
From cfd785f910fc914c576133fee263875833ba0c92 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Thu, 1 Sep 2011 21:20:26 +1200
Subject: Move css data URI into css/erb section
---
railties/guides/source/asset_pipeline.textile | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 3ed75a28ef..cfed1b5bdf 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -140,14 +140,6 @@ Images can also be organized into subdirectories if required, and they can be ac
<%= image_tag "icons/rails.png" %>
-If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper.
-
-
-#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
-
-
-This inserts a correctly-formatted data URI into the CSS source.
-
h5. CSS and ERB
If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules:
@@ -158,6 +150,14 @@ If you add an +erb+ extension to a CSS asset, making it something such as +appli
This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced.
+If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper.
+
+
+#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
+
+
+This inserts a correctly-formatted data URI into the CSS source.
+
Note that the closing tag cannot be of the style +-%>+.
h5. CSS and SCSS
--
cgit v1.2.3
From 3461a5d4368ab0e41f28d831170794f967286611 Mon Sep 17 00:00:00 2001
From: Roy Tomeij
Date: Thu, 1 Sep 2011 17:24:26 +0200
Subject: Change "SCSS" to "Sass" in sentences where it's referred to as
"language", because Sass is the language (SCSS is one possible syntax within
the Sass language), as per documentation on sass-lang.com.
---
railties/guides/source/asset_pipeline.textile | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index cfed1b5bdf..550485d038 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -13,7 +13,7 @@ endprologue.
h3. What is the Asset Pipeline?
-The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB.
+The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.
Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through ActionPack which depends on the +sprockets+ gem, by default.
@@ -36,7 +36,7 @@ The default behavior in Rails 3.1 and onward is to concatenate all files into on
The second feature is to minify or compress assets. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own.
-The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for JavaScript, and ERB for both.
+The third feature is the ability to code these assets using another language, or language extension. These include Sass for CSS, CoffeeScript for JavaScript, and ERB for both.
h4. What is Fingerprinting and Why Should I Care?
@@ -108,7 +108,7 @@ Assets can be placed inside an application in one of three locations: +app/asset
All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are traversed to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served.
You can add additional (fully qualified) paths to the pipeline in +application.rb+. For example:
-
+
config.assets.paths << File.join(Rails.root, 'app', 'assets', 'flash')
@@ -160,7 +160,7 @@ This inserts a correctly-formatted data URI into the CSS source.
Note that the closing tag cannot be of the style +-%>+.
-h5. CSS and SCSS
+h5. CSS and Sass
When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, javascript, stylesheet.
@@ -289,7 +289,7 @@ generates something like this:
-The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else).
+The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else).
NOTE: Under normal circumstances the default options should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes.
--
cgit v1.2.3
From 8e900f1e38166ea906967eb8ede9bd14e78eb417 Mon Sep 17 00:00:00 2001
From: Andy Leeper
Date: Thu, 1 Sep 2011 10:42:28 -0700
Subject: Modified ActionMailer Basics doc with the following change: * Changed
the lines that said config/environments/env.rb to
config/environments/$RAILS_ENV.rb. People were mis-interpreting the
filename to literally be env.rb.
---
railties/guides/source/action_mailer_basics.textile | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 142b9dba7e..351a4498b1 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -467,7 +467,7 @@ The following configuration options are best made in one of the environment file
h4. Example Action Mailer Configuration
-An example would be adding the following to your appropriate config/environments/env.rb file:
+An example would be adding the following to your appropriate config/environments/$RAILS_ENV.rb file:
config.action_mailer.delivery_method = :sendmail
@@ -482,7 +482,7 @@ config.action_mailer.raise_delivery_errors = true
h4. Action Mailer Configuration for GMail
-As Action Mailer now uses the Mail gem, this becomes as simple as adding to your config/environments/env.rb file:
+As Action Mailer now uses the Mail gem, this becomes as simple as adding to your config/environments/$RAILS_ENV.rb file:
config.action_mailer.delivery_method = :smtp
@@ -524,4 +524,5 @@ In the test we send the email and store the returned object in the +email+ varia
h3. Changelog
+* September 1, 2011: Changed the lines that said config/environments/env.rb to config/environments/$RAILS_ENV.rb. People were mis-interpreting the filename to literally be env.rb. "Andy Leeper":http://mochaleaf.com
* September 30, 2010: Fixed typos and reformatted Action Mailer configuration table for better understanding. "Jaime Iniesta":http://jaimeiniesta.com
--
cgit v1.2.3
From c96cb8897b4afb0fea7b5fed4ec41d1772d99644 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 1 Sep 2011 23:50:31 +0530
Subject: Revert "Fix logic in 3.1 release notes sentence"
This reverts commit 30d65da17e5fb1cdd3f10a6d14f4295b57e26286.
Reason: This commit is incorrect. It is indeed recommended to use
update_attribute when you want callbacks to be invoked.
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 7de8866ff6..4412d32cce 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -271,7 +271,7 @@ Post.new(params[:post], :as => :admin)
* +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed.
-* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is not recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
+* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
* Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations.
--
cgit v1.2.3
From 2d92962701d545c29ebd38f51b787e48faabb504 Mon Sep 17 00:00:00 2001
From: Sebastian Martinez
Date: Thu, 1 Sep 2011 16:02:08 -0300
Subject: Add #update_attributes as another alternative to #update_column.
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 4412d32cce..73a96388af 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -271,7 +271,7 @@ Post.new(params[:post], :as => :admin)
* +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed.
-* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
+* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attributes+ or +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
* Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations.
--
cgit v1.2.3
From ca7c37a660b66b6b3cdd7fe4ab850ea5a32cc2c0 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Fri, 2 Sep 2011 08:39:16 +1200
Subject: fix some minor omissions in pipeline docs
---
railties/guides/source/asset_pipeline.textile | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 550485d038..e40310a9ec 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -89,6 +89,8 @@ In previous versions of Rails, all assets were located in subdirectories of +pub
This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served.
+In production, the default is to precompile these files to +public/assets+ so that they can be more efficiently delivered by the webserver.
+
When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller.
For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
@@ -241,11 +243,13 @@ This manifest +application.js+:
would generate this HTML:
-
-
-
+
+
+
+The +body+ param is required by Sprockets.
+
h4. Turning Debugging off
You can turn off debug mode by updating +development.rb+ to include:
@@ -264,7 +268,16 @@ Assets are compiled and cached on the first request after the server is started.
If any of the files in the manifest have changed between requests, the server responds with a new compiled file.
-You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render indivudual tags for each file. This is useful for tracking down exact line numbers when debugging.
+You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render individual tags for each file. This is useful for tracking down exact line numbers when debugging.
+
+Debug can also be set in the Rails helper methods:
+
+
+<%= stylesheet_link_tag "application", :debug => true %>
+<%= javascript_include_tag "application", :debug => true %>
+
+
+Don't forget to remove this before deploying to production!
You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging.
@@ -291,7 +304,7 @@ generates something like this:
The fingerprinting behavior is controlled by the setting of +config.assets.digest+ setting in Rails (which is +true+ for production, +false+ for everything else).
-NOTE: Under normal circumstances the default options should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes.
+NOTE: Under normal circumstances the default option should not be changed. If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes.
h4. Precompiling Assets
--
cgit v1.2.3
From 16aa4330d7a07736ce59ea3a96e57d17fa628a2d Mon Sep 17 00:00:00 2001
From: "Stephen J. Butler"
Date: Thu, 1 Sep 2011 19:55:38 -0500
Subject: Change the styling of 'initialize' to '+initialize+'
(the former breaks the HTML generation).
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 9cc4dd5f04..8aabc3ae91 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
TOPLEVEL_BINDING, config
-The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
+The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
require ::File.expand_path('../config/environment', __FILE__)
--
cgit v1.2.3
From 3a7c16dbb9c1a4ea96c516c0a9f9ce5d34cee49a Mon Sep 17 00:00:00 2001
From: Matt Burke
Date: Fri, 2 Sep 2011 10:20:23 -0400
Subject: When a collection is empty, render returns nil.
---
railties/guides/source/layouts_and_rendering.textile | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 310a70ca9b..3252f17c56 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -1093,6 +1093,13 @@ In Rails 3.0, there is also a shorthand for this. Assuming +@products+ is a coll
Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:
+In the event that the collection is empty, +render+ will return nil, so it should be fairly simple to provide alternative content.
+
+
+
Products
+<%= render(@products) || 'There are no products available.' %>
+
+
* +index.html.erb+
--
cgit v1.2.3
From d20281add192e5afba66e555ce67cf73943b033b Mon Sep 17 00:00:00 2001
From: Andrew Olson
Date: Fri, 2 Sep 2011 11:48:45 -0400
Subject: Fixing guides validation errors.
---
railties/guides/source/action_view_overview.textile | 6 +++---
railties/guides/source/active_model_basics.textile | 2 ++
railties/guides/source/active_record_querying.textile | 4 ++--
railties/guides/source/active_support_core_extensions.textile | 4 ++--
railties/guides/source/ajax_on_rails.textile | 6 +++++-
railties/guides/source/asset_pipeline.textile | 6 +++---
railties/guides/source/form_helpers.textile | 2 +-
railties/guides/source/generators.textile | 2 +-
railties/guides/source/initialization.textile | 6 +++---
railties/guides/source/performance_testing.textile | 4 ++--
10 files changed, 24 insertions(+), 18 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index 5a1e8b1247..c43fd8cc14 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -126,7 +126,7 @@ Rails supports multiple template systems and uses a file extension to distinguis
h5. ERB
-Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output.
+Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output.
Consider the following loop for names:
@@ -137,14 +137,14 @@ Consider the following loop for names:
<% end %>
-The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
+The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
<%# WRONG %>
Hi, Mr. <% puts "Frodo" %>
-To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+.
+To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+.
h5. Builder
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 0672669dc5..73df567579 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -163,12 +163,14 @@ person.first_name_changed? #=> true
Track what was the previous value of the attribute.
+
#attr_name_was accessor
person.first_name_was #=> "First Name"
Track both previous and current value of the changed attribute. Returns an array if changed else returns nil
+
#attr_name_change
person.first_name_change #=> ["First Name", "First Name 1"]
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 4e77a6e803..3a163fb943 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
Model.last returns +nil+ if no matching record is found. No exception will be raised.
-h5. +first!+
+h5(#first-1). +first!+
Model.first! finds the first record. For example:
@@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1
Model.first! raises +RecordNotFound+ if no matching record is found.
-h5. +last!+
+h5(#last-1). +last!+
Model.last! finds the last record. For example:
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index b2436a2e68..aab14dac8d 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -190,7 +190,7 @@ WARNING: Fixnums and symbols have no singleton classes, +singleton_class+ raises
NOTE: Defined in +active_support/core_ext/kernel/singleton_class.rb+.
-h4. +class_eval(*args, &block)+
+h4. +class_eval(*args, &block)+
You can evaluate code in the context of any object's singleton class using +class_eval+:
@@ -2097,7 +2097,7 @@ NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+.
h4. Options Extraction
-When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets:
+When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets:
User.exists?(:email => params[:email])
diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile
index 77f7661deb..e189c49bcd 100644
--- a/railties/guides/source/ajax_on_rails.textile
+++ b/railties/guides/source/ajax_on_rails.textile
@@ -67,7 +67,7 @@ link_to_remote "Add to cart",
If the server returns 200, the output of the above example is equivalent to our first, simple one. However, in case of error, the element with the DOM id +error+ is updated rather than the +cart+ element.
-** *position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities:
+** *:position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities:
*** +:before+ Inserts the response text just before the target element. More precisely, it creates a text node from the response and inserts it as the left sibling of the target element.
*** +:after+ Similar behavior to +:before+, but in this case the response is inserted after the target element.
*** +:top+ Inserts the text into the target element, before it's original content. If the target element was empty, this is equivalent with not specifying +:position+ at all.
@@ -123,7 +123,9 @@ link_to_remote "Add new item",
:update => "item_list",
404 => "alert('Item not found!')"
+
Let's see a typical example for the most frequent callbacks, +:success+, +:failure+ and +:complete+ in action:
+
link_to_remote "Add new item",
:url => items_url,
@@ -133,7 +135,9 @@ link_to_remote "Add new item",
:success => "display_item_added(request)",
:failure => "display_error(request)"
+
** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+.
+
* Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though:
** If you specify the +href+ parameter, the AJAX link will degrade gracefully, i.e. the link will point to the URL even if JavaScript is disabled in the client browser
** +link_to_remote+ gains it's AJAX behavior by specifying the remote call in the onclick handler of the link. If you supply +html_options[:onclick]+ you override the default behavior, so use this with care!
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index cfed1b5bdf..bbd2e24da5 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -62,11 +62,11 @@ This has several disadvantages:
- Not all caches will cache content with a query string
+ Not all caches will cache content with a query string
"Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached.
- The file name can change between nodes in multi-server environments.
+ The file name can change between nodes in multi-server environments.
The query string in Rails is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request.
@@ -91,7 +91,7 @@ This is not to say that assets can (or should) no longer be placed in +public+;
When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller.
-For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
+For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index c277f5723a..9b35c409b3 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -98,7 +98,7 @@ form_tag({:controller => "people", :action => "search"}, :method => "get", :clas
h4. Helpers for Generating Form Elements
-Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+.
+Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+.
When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in +params+. You can read more about them in "chapter 7 of this guide":#understanding-parameter-naming-conventions. For details on the precise usage of these helpers, please refer to the "API documentation":http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html.
diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile
index 2fa1d6e21d..24f100187a 100644
--- a/railties/guides/source/generators.textile
+++ b/railties/guides/source/generators.textile
@@ -1,4 +1,4 @@
-h2. Creating and Customizing Rails Generators & Templates
+h2. Creating and Customizing Rails Generators & Templates
Rails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones.
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 9cc4dd5f04..3804f5e81f 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
TOPLEVEL_BINDING, config
-The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
+The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
require ::File.expand_path('../config/environment', __FILE__)
@@ -676,11 +676,11 @@ h4. Back to +railties/lib/rails/railtie.rb+
Once the inflector files have been loaded, the +Rails::Railtie+ class is defined. This class includes a module called +Initializable+, which is actually +Rails::Initializable+. This module includes the +initializer+ method which is used later on for setting up initializers, amongst other methods.
-h4. +railties/lib/rails/initializable.rb+
+h4(#railties-lib-rails-initializable-rb-1). +railties/lib/rails/initializable.rb+
When the module from this file (+Rails::Initializable+) is included, it extends the class it's included into with the +ClassMethods+ module inside of it. This module defines the +initializer+ method which is used to define initializers throughout all of the railties. This file completes the loading of +railties/lib/rails/railtie.rb+. Now we go back to +rails/engine.rb+.
-h4. +railties/lib/rails/engine.rb+
+h4(#railties-lib-rails-engine-rb-1). +railties/lib/rails/engine.rb+
The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation.
diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index 75f81cf13d..0ea88d8385 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case.
h5. Metric Availability
-h6. Benchmarking
+h6(#benchmarking-1). Benchmarking
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|_.MRI | yes | yes | yes | no | yes | yes | yes | yes |
@@ -215,7 +215,7 @@ h6. Benchmarking
|_.Rubinius | yes | no | no | no | yes | yes | yes | yes |
|_.JRuby | yes | no | no | yes | yes | yes | yes | yes |
-h6. Profiling
+h6(#profiling-1). Profiling
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|_.MRI | yes | yes | no | no | yes | yes | yes | yes |
--
cgit v1.2.3
From 220c77dd68430cc150c61119a14c86dee659911c Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 2 Sep 2011 22:42:23 +0530
Subject: debug option to js, stylesheet tags are ignored when debug mode is
off
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 73f77ac05e..86ae23ab11 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -277,7 +277,7 @@ Debug can also be set in the Rails helper methods:
<%= javascript_include_tag "application", :debug => true %>
-Don't forget to remove this before deploying to production!
+The +:debug+ option is ignored if the debug mode is off.
You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging.
--
cgit v1.2.3
From 44284a613b3efe2319db3f84090c0004505942c1 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 2 Sep 2011 22:57:03 +0530
Subject: Revert "Fixing guides validation errors."
This reverts commit d20281add192e5afba66e555ce67cf73943b033b.
Reason: This needs more investigation. Will apply when this is verified.
---
railties/guides/source/action_view_overview.textile | 6 +++---
railties/guides/source/active_model_basics.textile | 2 --
railties/guides/source/active_record_querying.textile | 4 ++--
railties/guides/source/active_support_core_extensions.textile | 4 ++--
railties/guides/source/ajax_on_rails.textile | 6 +-----
railties/guides/source/asset_pipeline.textile | 6 +++---
railties/guides/source/form_helpers.textile | 2 +-
railties/guides/source/generators.textile | 2 +-
railties/guides/source/initialization.textile | 6 +++---
railties/guides/source/performance_testing.textile | 4 ++--
10 files changed, 18 insertions(+), 24 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index c43fd8cc14..5a1e8b1247 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -126,7 +126,7 @@ Rails supports multiple template systems and uses a file extension to distinguis
h5. ERB
-Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output.
+Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output.
Consider the following loop for names:
@@ -137,14 +137,14 @@ Consider the following loop for names:
<% end %>
-The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
+The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
<%# WRONG %>
Hi, Mr. <% puts "Frodo" %>
-To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+.
+To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+.
h5. Builder
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 73df567579..0672669dc5 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -163,14 +163,12 @@ person.first_name_changed? #=> true
Track what was the previous value of the attribute.
-
#attr_name_was accessor
person.first_name_was #=> "First Name"
Track both previous and current value of the changed attribute. Returns an array if changed else returns nil
-
#attr_name_change
person.first_name_change #=> ["First Name", "First Name 1"]
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 3a163fb943..4e77a6e803 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
Model.last returns +nil+ if no matching record is found. No exception will be raised.
-h5(#first-1). +first!+
+h5. +first!+
Model.first! finds the first record. For example:
@@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1
Model.first! raises +RecordNotFound+ if no matching record is found.
-h5(#last-1). +last!+
+h5. +last!+
Model.last! finds the last record. For example:
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index aab14dac8d..b2436a2e68 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -190,7 +190,7 @@ WARNING: Fixnums and symbols have no singleton classes, +singleton_class+ raises
NOTE: Defined in +active_support/core_ext/kernel/singleton_class.rb+.
-h4. +class_eval(*args, &block)+
+h4. +class_eval(*args, &block)+
You can evaluate code in the context of any object's singleton class using +class_eval+:
@@ -2097,7 +2097,7 @@ NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+.
h4. Options Extraction
-When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets:
+When the last argument in a method call is a hash, except perhaps for a +&block+ argument, Ruby allows you to omit the brackets:
User.exists?(:email => params[:email])
diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile
index e189c49bcd..77f7661deb 100644
--- a/railties/guides/source/ajax_on_rails.textile
+++ b/railties/guides/source/ajax_on_rails.textile
@@ -67,7 +67,7 @@ link_to_remote "Add to cart",
If the server returns 200, the output of the above example is equivalent to our first, simple one. However, in case of error, the element with the DOM id +error+ is updated rather than the +cart+ element.
-** *:position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities:
+** *position* By default (i.e. when not specifying this option, like in the examples before) the response is injected into the element with the specified DOM id, replacing the original content of the element (if there was any). You might want to alter this behavior by keeping the original content - the only question is where to place the new content? This can specified by the +position+ parameter, with four possibilities:
*** +:before+ Inserts the response text just before the target element. More precisely, it creates a text node from the response and inserts it as the left sibling of the target element.
*** +:after+ Similar behavior to +:before+, but in this case the response is inserted after the target element.
*** +:top+ Inserts the text into the target element, before it's original content. If the target element was empty, this is equivalent with not specifying +:position+ at all.
@@ -123,9 +123,7 @@ link_to_remote "Add new item",
:update => "item_list",
404 => "alert('Item not found!')"
-
Let's see a typical example for the most frequent callbacks, +:success+, +:failure+ and +:complete+ in action:
-
link_to_remote "Add new item",
:url => items_url,
@@ -135,9 +133,7 @@ link_to_remote "Add new item",
:success => "display_item_added(request)",
:failure => "display_error(request)"
-
** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+.
-
* Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though:
** If you specify the +href+ parameter, the AJAX link will degrade gracefully, i.e. the link will point to the URL even if JavaScript is disabled in the client browser
** +link_to_remote+ gains it's AJAX behavior by specifying the remote call in the onclick handler of the link. If you supply +html_options[:onclick]+ you override the default behavior, so use this with care!
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 86ae23ab11..192c393dca 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -62,11 +62,11 @@ This has several disadvantages:
- Not all caches will cache content with a query string
+ Not all caches will cache content with a query string
"Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached.
- The file name can change between nodes in multi-server environments.
+ The file name can change between nodes in multi-server environments.
The query string in Rails is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request.
@@ -93,7 +93,7 @@ In production, the default is to precompile these files to +public/assets+ so th
When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller.
-For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
+For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index 9b35c409b3..c277f5723a 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -98,7 +98,7 @@ form_tag({:controller => "people", :action => "search"}, :method => "get", :clas
h4. Helpers for Generating Form Elements
-Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+.
+Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as +text_field_tag+ and +check_box_tag+), generate just a single +<input>+ element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the +params+ hash in the controller with the value entered by the user for that field. For example, if the form contains +<%= text_field_tag(:query) %>+, then you would be able to get the value of this field in the controller with +params[:query]+.
When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in +params+. You can read more about them in "chapter 7 of this guide":#understanding-parameter-naming-conventions. For details on the precise usage of these helpers, please refer to the "API documentation":http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html.
diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile
index 24f100187a..2fa1d6e21d 100644
--- a/railties/guides/source/generators.textile
+++ b/railties/guides/source/generators.textile
@@ -1,4 +1,4 @@
-h2. Creating and Customizing Rails Generators & Templates
+h2. Creating and Customizing Rails Generators & Templates
Rails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones.
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 3804f5e81f..9cc4dd5f04 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
TOPLEVEL_BINDING, config
-The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
+The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
require ::File.expand_path('../config/environment', __FILE__)
@@ -676,11 +676,11 @@ h4. Back to +railties/lib/rails/railtie.rb+
Once the inflector files have been loaded, the +Rails::Railtie+ class is defined. This class includes a module called +Initializable+, which is actually +Rails::Initializable+. This module includes the +initializer+ method which is used later on for setting up initializers, amongst other methods.
-h4(#railties-lib-rails-initializable-rb-1). +railties/lib/rails/initializable.rb+
+h4. +railties/lib/rails/initializable.rb+
When the module from this file (+Rails::Initializable+) is included, it extends the class it's included into with the +ClassMethods+ module inside of it. This module defines the +initializer+ method which is used to define initializers throughout all of the railties. This file completes the loading of +railties/lib/rails/railtie.rb+. Now we go back to +rails/engine.rb+.
-h4(#railties-lib-rails-engine-rb-1). +railties/lib/rails/engine.rb+
+h4. +railties/lib/rails/engine.rb+
The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation.
diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index 0ea88d8385..75f81cf13d 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case.
h5. Metric Availability
-h6(#benchmarking-1). Benchmarking
+h6. Benchmarking
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|_.MRI | yes | yes | yes | no | yes | yes | yes | yes |
@@ -215,7 +215,7 @@ h6(#benchmarking-1). Benchmarking
|_.Rubinius | yes | no | no | no | yes | yes | yes | yes |
|_.JRuby | yes | no | no | yes | yes | yes | yes | yes |
-h6(#profiling-1). Profiling
+h6. Profiling
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|_.MRI | yes | yes | no | no | yes | yes | yes | yes |
--
cgit v1.2.3
From 78497c7c27879aa735db24377f056de96a260bb9 Mon Sep 17 00:00:00 2001
From: Franco Catena
Date: Fri, 2 Sep 2011 14:52:58 -0300
Subject: Change photos_path to photos_url in Using redirect_to
Is more "correct" a complete url than only the path
---
railties/guides/source/layouts_and_rendering.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 3252f17c56..f49c2000ee 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -515,7 +515,7 @@ h4. Using +redirect_to+
Another way to handle returning responses to an HTTP request is with +redirect_to+. As you've seen, +render+ tells Rails which view (or other asset) to use in constructing a response. The +redirect_to+ method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:
-redirect_to photos_path
+redirect_to photos_url
You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. In addition, there's a special redirect that sends the user back to the page they just came from:
--
cgit v1.2.3
From f83f169b85eea4f580ae95609506fbb3cc5b8ccb Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 3 Sep 2011 01:40:00 +0530
Subject: some of the changes for validation earlier reverted from d20281a
---
railties/guides/source/active_model_basics.textile | 2 ++
railties/guides/source/active_record_querying.textile | 4 ++--
railties/guides/source/performance_testing.textile | 4 ++--
3 files changed, 6 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 0672669dc5..73df567579 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -163,12 +163,14 @@ person.first_name_changed? #=> true
Track what was the previous value of the attribute.
+
#attr_name_was accessor
person.first_name_was #=> "First Name"
Track both previous and current value of the changed attribute. Returns an array if changed else returns nil
+
#attr_name_change
person.first_name_change #=> ["First Name", "First Name 1"]
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 4e77a6e803..95a7bfebc3 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
Model.last returns +nil+ if no matching record is found. No exception will be raised.
-h5. +first!+
+h5(#first_1). +first!+
Model.first! finds the first record. For example:
@@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1
Model.first! raises +RecordNotFound+ if no matching record is found.
-h5. +last!+
+h5(#last_1). +last!+
Model.last! finds the last record. For example:
diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index 75f81cf13d..5947735deb 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case.
h5. Metric Availability
-h6. Benchmarking
+h6(#benchmarking_1). Benchmarking
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|_.MRI | yes | yes | yes | no | yes | yes | yes | yes |
@@ -215,7 +215,7 @@ h6. Benchmarking
|_.Rubinius | yes | no | no | no | yes | yes | yes | yes |
|_.JRuby | yes | no | no | yes | yes | yes | yes | yes |
-h6. Profiling
+h6(#profiling_1). Profiling
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|_.MRI | yes | yes | no | no | yes | yes | yes | yes |
--
cgit v1.2.3
From b3a03253a78234dfc3bef0fab7dae2e49c2bfd2a Mon Sep 17 00:00:00 2001
From: David Peckham
Date: Fri, 2 Sep 2011 13:38:13 -0700
Subject: Fixed a typo in the section about migration.
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 256df0eded..6e9613cdae 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -592,7 +592,7 @@ class CreatePosts < ActiveRecord::Migration
end
-The above migration creates a method name +change+ which will be called when you
+The above migration creates a method named +change+ which will be called when you
run this migration. The action defined in that method is also reversible, which
means Rails knows how to reverse the change made by this migration, in case you
want to reverse it at later date. By default, when you run this migration it
--
cgit v1.2.3
From a3edf3d2a307630980731b1963721c60ba2a14e0 Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Sat, 3 Sep 2011 09:11:20 +1200
Subject: fix YUI description
YUI CSS compressor does not extend syntax! Also
added link to more info
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 192c393dca..ef35d1ed76 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -437,7 +437,7 @@ h3. Customizing the Pipeline
h4. CSS Compression
-There is currently one option for compressing CSS, YUI. This Gem extends the CSS syntax and offers minification.
+There is currently one option for compressing CSS, YUI. The "YUI CSS compressor":http://developer.yahoo.com/yui/compressor/css.html provides minification.
The following line enables YUI compression, and requires the +yui-compressor+ gem.
--
cgit v1.2.3
From 5b7bcb4959a33d7a31acdd2823eb3272bcd1f322 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 3 Sep 2011 02:44:49 +0530
Subject: document send_file guesses content type from the file extension and
remove info about x_send_file option to send_file
---
railties/guides/source/action_controller_overview.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile
index 073e3bddcf..4e47712636 100644
--- a/railties/guides/source/action_controller_overview.textile
+++ b/railties/guides/source/action_controller_overview.textile
@@ -684,9 +684,11 @@ end
This will read and stream the file 4kB at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the +:stream+ option or adjust the block size with the +:buffer_size+ option.
+If +:type+ is not specified, it will be guessed from the file extension specified in +:filename+. If the content type is not registered for the extension, application/octet-stream will be used.
+
WARNING: Be careful when using data coming from the client (params, cookies, etc.) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see.
-TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. Although if you do need the request to go through Rails for some reason, you can set the +:x_sendfile+ option to true, and Rails will let the web server handle sending the file to the user, freeing up the Rails process to do other things. Note that your web server needs to support the +X-Sendfile+ header for this to work.
+TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack.
h4. RESTful Downloads
--
cgit v1.2.3
From 1b8290db527e29c6b503cb036bc42d67368f766c Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Fri, 2 Sep 2011 17:10:11 -0500
Subject: Fix asset_path example in CSS and ERB section
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index ef35d1ed76..82aa0a5256 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -147,7 +147,7 @@ h5. CSS and ERB
If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules:
-.class { background-image: <%= asset_path 'image.png' %> }
+.class { background-image: url(<%= asset_path 'image.png') %> }
This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced.
--
cgit v1.2.3
From 5912ed99029f76b3ec51955f05323b77fa0b22f2 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Sat, 3 Sep 2011 01:36:57 +0200
Subject: fixes CSS example in the asset pipeline guide
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 192c393dca..6935533f4a 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -147,7 +147,7 @@ h5. CSS and ERB
If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules:
-.class { background-image: <%= asset_path 'image.png' %> }
+.class { background-image: url(<%= asset_path 'image.png' %>) }
This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced.
--
cgit v1.2.3
From 5014b330288d41680477800847e83e049a5b57c3 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 4 Sep 2011 03:44:47 +0530
Subject: add some missing dots in the docs
---
railties/guides/source/configuring.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 050fcd823d..ae84bb5b92 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -134,15 +134,15 @@ Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets wit
* +config.assets.prefix+ defines the prefix where assets are served from. Defaults to +/assets+.
-* +config.assets.digest+ enables the use of MD5 fingerprints in asset names. Set to +true+ by default in +production.rb+
+* +config.assets.digest+ enables the use of MD5 fingerprints in asset names. Set to +true+ by default in +production.rb+.
-* +config.assets.debug+ disables the concatenation and compression of assets. Set to +false+ by default in +development.rb+
+* +config.assets.debug+ disables the concatenation and compression of assets. Set to +false+ by default in +development.rb+.
-* +config.assets.manifest+ defines the full path to be used for the asset precompiler's manifest file. Defaults to using +config.assets.prefix+
+* +config.assets.manifest+ defines the full path to be used for the asset precompiler's manifest file. Defaults to using +config.assets.prefix+.
* +config.assets.cache_store+ defines the cache store that Sprockets will use. The default is the Rails file store.
-* +config.assets.version+ is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.
+* +config.assets.version+ is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.
* +config.assets.compile+ is a boolean that can be used to turn on live Sprockets compilation in production.
--
cgit v1.2.3
From a6c60222c580e4002152b1ac1857673038b1fd42 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 4 Sep 2011 08:24:02 +0530
Subject: Modified content in guides and comments for "assert /" warnings.
Removed because if somebody will use this code they will get warnings!
---
railties/guides/source/action_mailer_basics.textile | 4 ++--
railties/guides/source/testing.textile | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 351a4498b1..67761645fa 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -514,8 +514,8 @@ class UserMailerTest < ActionMailer::TestCase
# Test the body of the sent email contains what we expect it to
assert_equal [user.email], email.to
assert_equal "Welcome to My Awesome Site", email.subject
- assert_match /
Welcome to example.com, #{user.name}<\/h1>/, email.encoded
- assert_match /Welcome to example.com, #{user.name}/, email.encoded
+ assert_match(/
Welcome to example.com, #{user.name}<\/h1>/, email.encoded)
+ assert_match(/Welcome to example.com, #{user.name}/, email.encoded)
end
end
diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile
index cc55d1f756..caa0d91a83 100644
--- a/railties/guides/source/testing.textile
+++ b/railties/guides/source/testing.textile
@@ -931,7 +931,7 @@ class UserControllerTest < ActionController::TestCase
assert_equal "You have been invited by me@example.com", invite_email.subject
assert_equal 'friend@example.com', invite_email.to[0]
- assert_match /Hi friend@example.com/, invite_email.body
+ assert_match(/Hi friend@example.com/, invite_email.body)
end
end
--
cgit v1.2.3
From d72ecd92a270823e2fd400066e3c3c55a9bda478 Mon Sep 17 00:00:00 2001
From: Rinaldi Fonseca
Date: Sun, 4 Sep 2011 00:34:56 -0300
Subject: Added |t| to create_table block
---
railties/guides/source/3_1_release_notes.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile
index 73a96388af..c4da87dc34 100644
--- a/railties/guides/source/3_1_release_notes.textile
+++ b/railties/guides/source/3_1_release_notes.textile
@@ -315,7 +315,7 @@ end
class MyMigration < ActiveRecord::Migration
def change
- create_table(:horses) do
+ create_table(:horses) do |t|
t.column :content, :text
t.column :remind_at, :datetime
end
--
cgit v1.2.3
From b84cee08c6129717d7c3291918f06f95cc9eb916 Mon Sep 17 00:00:00 2001
From: Prem Sichanugrist
Date: Fri, 2 Sep 2011 21:35:24 +0700
Subject: Make `content_tag_for` and `div_for` accepts the array of records
So instead of having to do this:
@items.each do |item|
content_tag_for(:li, item) do
Title: <%= item.title %>
end
end
You can now do this:
content_tag_for(:li, @items) do |item|
Title: <%= item.title %>
end
---
.../guides/source/action_view_overview.textile | 77 ++++++++++++++++++++++
1 file changed, 77 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index 5a1e8b1247..d1827c649b 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -454,6 +454,83 @@ input("post", "title") # =>
+h4. RecordTagHelper
+
+This module provides methods for generating a container tag, such as a +
+, for your record. This is the recommended way of creating a container for render your Active Record object, as it adds an appropriate class and id attributes to that container. You can then refer to those containers easily by following the convention, instead of having to think about which class or id attribute you should use.
+
+h5. content_tag_for
+
+Renders a container tag that relates to your Active Record Object.
+
+For example, given +@post+ is the object of +Post+ class, you can do:
+
+
+<%= content_tag_for(:tr, @post) do %>
+
<%= @post.title %>
+<% end %>
+
+
+This will generate this HTML output:
+
+
+
+
Hello World!
+
+
+
+You can also supply HTML attributes as an additional option hash. For example:
+
+
+<%= content_tag_for(:tr, @post, :class => "frontpage") do %>
+
<%= @post.title %>
+<% end %>
+
+
+Will generate this HTML output:
+
+
+
+
Hello World!
+
+
+
+You can pass a collection of Active Record objects. This method will loops through your objects and create a container for each of them. For example, given +@posts+ is an array of two +Post+ objects:
+
+
+<%= content_tag_for(:tr, @posts) do |post| %>
+
<%= post.title %>
+<% end %>
+
+
+Will generate this HTML output:
+
+
+
+
Hello World!
+
+
+
Ruby on Rails Rocks!
+
+
+
+h5. div_for
+
+This is actually a convenient method which calls +content_tag_for+ internally with +:div+ as the tag name. You can pass either an Active Record object or a collection of objects. For example:
+
+
+<%= div_for(@post, :class => "frontpage") do %>
+
<%= @post.title %>
+<% end %>
+
+
+Will generate this HTML output:
+
+
+
+
Hello World!
+
+
+
h4. AssetTagHelper
This module provides methods for generating HTML that links views to assets such as images, JavaScript files, stylesheets, and feeds.
--
cgit v1.2.3
From 47bc5d0cc8dec79c0c64ade7d453b60f846424a9 Mon Sep 17 00:00:00 2001
From: Wojciech Mach
Date: Sun, 4 Sep 2011 10:14:53 +0200
Subject: Add gem_group support to generators
---
railties/guides/source/generators.textile | 9 +++++++++
railties/guides/source/rails_application_templates.textile | 12 ++++++++++++
2 files changed, 21 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile
index 2fa1d6e21d..3f990ef54b 100644
--- a/railties/guides/source/generators.textile
+++ b/railties/guides/source/generators.textile
@@ -449,6 +449,15 @@ The above code will put the following line into +Gemfile+:
gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master"
+h4. +gem_group+
+
+Wraps gem entries inside a group:
+
+
+gem_group :development, :test do
+ gem "rspec-rails"
+end
+
h4. +add_source+
diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile
index 566f8a0bdd..c3c8af4d3a 100644
--- a/railties/guides/source/rails_application_templates.textile
+++ b/railties/guides/source/rails_application_templates.textile
@@ -60,6 +60,18 @@ Please note that this will NOT install the gems for you and you will have to run
bundle install
+h4. gem_group(*names, &block)
+
+Wraps gem entries inside a group.
+
+For example, if you want to load +rspec-rails+ only in +development+ and +test+ group:
+
+
+gem_group :development, :test do
+ gem "rspec-rails"
+end
+
+
h4. add_source(source, options = {})
Adds the given source to the generated application's +Gemfile+.
--
cgit v1.2.3
From a6bafb327d403361ef652d6749f0609cfc2a5578 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 4 Sep 2011 18:49:16 +0530
Subject: minor fixes in assets guide
---
railties/guides/source/asset_pipeline.textile | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 82aa0a5256..f287bcd511 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -15,11 +15,11 @@ h3. What is the Asset Pipeline?
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.
-Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through ActionPack which depends on the +sprockets+ gem, by default.
+Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through Action Pack which depends on the +sprockets+ gem, by default.
By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf.
-In new Rails 3.1 application the asset pipeline is enabled by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition:
+In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition:
config.assets.enabled = false
@@ -308,7 +308,7 @@ NOTE: Under normal circumstances the default option should not be changed. If th
h4. Precompiling Assets
-Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to disc.
+Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to the disk.
Compiled assets are written to the location specified in +config.assets.prefix+. The default setting will use the +public/assets+ directory.
@@ -361,7 +361,7 @@ This can be changed with the +config.assets.manifest+ option. A fully specified
config.assets.manifest = '/path/to/some/other/location'
-NOTE: If there are missing precompiled files in production you will get an "AssetNoPrecompiledError" exception indicating the name of the missing file.
+NOTE: If there are missing precompiled files in production you will get an AssetNoPrecompiledError exception indicating the name of the missing file(s).
h5. Server Configuration
@@ -385,7 +385,7 @@ For Apache:
TODO: nginx instructions
-When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used:
+When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disk. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used:
For Apache:
@@ -419,7 +419,7 @@ location ~ ^/(assets)/ {
h4. Live Compilation
-In some circumstances you may wish to use live compilation. In this mode all requests for assets in the Pipeline are handled by Sprockets directly.
+In some circumstances you may wish to use live compilation. In this mode all requests for assets in the pipeline are handled by Sprockets directly.
To enable this option set:
@@ -445,7 +445,7 @@ The following line enables YUI compression, and requires the +yui-compressor+ ge
config.assets.css_compressor = :yui
-The +config.assets.compress+ must be set to +true+ to enable CSS compression
+The +config.assets.compress+ must be set to +true+ to enable CSS compression.
h4. JavaScript Compression
@@ -539,8 +539,7 @@ config.assets.enabled = true
config.assets.version = '1.0'
# Change the path that assets are served from
-# config.assets.prefix = "/assets"
-
+# config.assets.prefix = "/assets"
In +development.rb+:
@@ -584,9 +583,8 @@ The following should also be added to +Gemfile+:
# Gems used only for assets and not required
# in production environments by default.
group :assets do
- gem 'sass-rails', " ~> 3.1.0"
+ gem 'sass-rails', "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
-
--
cgit v1.2.3
From 14157b779b9f65bb9d39cb38b100776f2fe1f194 Mon Sep 17 00:00:00 2001
From: Ray Baxter
Date: Sun, 4 Sep 2011 13:34:07 -0700
Subject: clarify where the branch name will exist
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 4706725bb6..c302d393aa 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -284,7 +284,7 @@ $ cd rails
$ git checkout -b my_new_branch
-It doesn’t really matter what name you use, because this branch will only exist on your local computer.
+It doesn’t really matter what name you use, because this branch will only exist on your local computer and your personal repository on Github. It won't be part of the Rails git repository.
h4. Write Your Code
--
cgit v1.2.3
From 0a2ea92efa52165d6b840f2f18382484388389d2 Mon Sep 17 00:00:00 2001
From: Hendy Tanata
Date: Mon, 5 Sep 2011 08:05:06 +0800
Subject: Fix grammar for content_tag_for and div_for docs.
---
railties/guides/source/action_view_overview.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index d1827c649b..edaaeb8543 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -494,7 +494,7 @@ Will generate this HTML output:
-You can pass a collection of Active Record objects. This method will loops through your objects and create a container for each of them. For example, given +@posts+ is an array of two +Post+ objects:
+You can pass a collection of Active Record objects. This method will loop through your objects and create a container for each of them. For example, given +@posts+ is an array of two +Post+ objects:
<%= content_tag_for(:tr, @posts) do |post| %>
--
cgit v1.2.3
From 3e62235c6c384775c0a12ba5683eba37fee8acd9 Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Sun, 4 Sep 2011 20:56:47 -0500
Subject: Add JavaScript and ERB section to Asset Guide
---
railties/guides/source/asset_pipeline.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 54464cdf4d..69b8d43f55 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -174,6 +174,18 @@ The more generic form can also be used but the asset path and class must both be
* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+
* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+
+h5. JavaScript and ERB
+
+If you add an +erb+ extension to a JavaScript asset, making it something such as +application.js.erb+, then you can use the +asset_path+ helper in your JavaScript code:
+
+
+$('#logo').attr({
+ src: "<%= asset_path('logo.png') %>"
+});
+
+
+This writes the path to the particular asset being referenced.
+
h4. Manifest Files and Directives
Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make.
--
cgit v1.2.3
From a1dbd94b60ee4118e4706f7bb3a416fcc215e0b5 Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Sun, 4 Sep 2011 21:01:04 -0500
Subject: Add CoffeeScript example to JavaScript and ERB section
---
railties/guides/source/asset_pipeline.textile | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 69b8d43f55..fdb18651dc 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -174,7 +174,7 @@ The more generic form can also be used but the asset path and class must both be
* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+
* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+
-h5. JavaScript and ERB
+h5. JavaScript/CoffeeScript and ERB
If you add an +erb+ extension to a JavaScript asset, making it something such as +application.js.erb+, then you can use the +asset_path+ helper in your JavaScript code:
@@ -186,6 +186,12 @@ $('#logo').attr({
This writes the path to the particular asset being referenced.
+Similary, you can use the asset_path helper in CoffeeScript files with +erb+ extension (Eg. application.js.coffee.erb):
+
+
+$('#logo').attr src: "<% asset_path('logo.png') %>"
+
+
h4. Manifest Files and Directives
Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make.
--
cgit v1.2.3
From 8df4fb1bb4e5109f734f396625efd8446253fbd4 Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Sun, 4 Sep 2011 21:17:23 -0500
Subject: Add reference about "bundle install --without assets" in Precompiling
Assets section.
---
railties/guides/source/asset_pipeline.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index fdb18651dc..1b2e81dc8b 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -348,6 +348,8 @@ This links the folder specified in +config.assets.prefix+ to +shared/assets+. If
It is important that this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page.
+Note: If you are precompiling your assets locally you can use +bundle install --without assets+ when installing the gems on the server to avoid install of the assets gems (the gems in the assets group in the Gemfile).
+
The default matcher for compiling files includes +application.js+, +application.css+ and all files that do not end in +js+ or +css+:
--
cgit v1.2.3
From a76c23e6bec3e418b9845010fc4c9f997abe1a01 Mon Sep 17 00:00:00 2001
From: dharmatech
Date: Mon, 5 Sep 2011 04:07:48 -0500
Subject: getting_started.textile: fix minor typo
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 6e9613cdae..e17b1ee1ee 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -63,7 +63,7 @@ The Rails philosophy includes several guiding principles:
* Convention Over Configuration - means that Rails makes assumptions about what you want to do and how you're going to
d o it, rather than requiring you to specify every little thing through endless configuration files.
* REST is the best pattern for web applications - organizing your application around resources and standard HTTP verbs
-i s the fastest way to go.
+is the fastest way to go.
h4. The MVC Architecture
--
cgit v1.2.3
From 9584e15d3967a9fd4b38dca26db2de68add96dd2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?U=C4=A3is=20Ozols?=
Date: Tue, 6 Sep 2011 17:13:30 +0300
Subject: Change hyphen to underscore.
---
railties/guides/source/asset_pipeline.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 1b2e81dc8b..1448776c25 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -166,13 +166,13 @@ h5. CSS and Sass
When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, javascript, stylesheet.
-* +image-url("rails.png")+ becomes +url(/assets/rails.png)+
-* +image-path("rails.png")+ becomes +"/assets/rails.png"+.
+* +image_url("rails.png")+ becomes +url(/assets/rails.png)+
+* +image_path("rails.png")+ becomes +"/assets/rails.png"+.
The more generic form can also be used but the asset path and class must both be specified:
-* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+
-* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+
+* +asset_url("rails.png", image)+ becomes +url(/assets/rails.png)+
+* +asset_path("rails.png", image)+ becomes +"/assets/rails.png"+
h5. JavaScript/CoffeeScript and ERB
--
cgit v1.2.3
From 5e2bf4de62014820798b271e97fa010ddc1a7e02 Mon Sep 17 00:00:00 2001
From: Marcus Ilgner
Date: Tue, 6 Sep 2011 16:27:26 +0200
Subject: Fixed Apache configuration for gzipped assets: FilesMatch and
LocationMatch cannot be nested.
---
railties/guides/source/asset_pipeline.textile | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 1448776c25..e4f1e0c41a 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -414,16 +414,16 @@ For Apache:
# 2 lines to serve pre-gzipped version
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
-
- # without it, Content-Type will be "application/x-gzip"
-
- ForceType text/css
-
-
-
- ForceType text/javascript
-
+
+# without these, Content-Type will be "application/x-gzip"
+
+ ForceType text/css
+
+
+
+ ForceType text/javascript
+
For nginx:
--
cgit v1.2.3
From 198092e2c0a703ca983893aa4527317b3442b5b1 Mon Sep 17 00:00:00 2001
From: Ryan Walker
Date: Tue, 6 Sep 2011 14:06:34 -0300
Subject: Added note about adding a javascript runtime to Gemfile for
production environment.
---
railties/guides/source/asset_pipeline.textile | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index e4f1e0c41a..b6f8d607b9 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -608,3 +608,11 @@ group :assets do
gem 'uglifier'
end
+
+Rails 3.1 requires "execjs":https://github.com/sstephenson/execjs - but it doesn't provide a default javascript runtime. When deploying a production app to a system without a pre-existing javascript runtime, you may want to add:
+
+
+group :production do
+ gem 'therubyracer'
+end
+
--
cgit v1.2.3
From 760fd1eb42038a64591036fc5d687afc98f272aa Mon Sep 17 00:00:00 2001
From: Joost Baaij
Date: Wed, 7 Sep 2011 16:09:56 +0300
Subject: Rails.root is a Pathname, no need to use File.join first.
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index b6f8d607b9..f2b93be35f 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -112,7 +112,7 @@ All subdirectories that exist within these three locations are added to the sear
You can add additional (fully qualified) paths to the pipeline in +application.rb+. For example:
-config.assets.paths << File.join(Rails.root, 'app', 'assets', 'flash')
+config.assets.paths << Rails.root.join('app', 'assets', 'flash')
h4. Coding Links to Assets
--
cgit v1.2.3
From 98b55ee2e3d89a050359a52bcc203bfe4fbc39ed Mon Sep 17 00:00:00 2001
From: dharmatech
Date: Wed, 7 Sep 2011 09:09:11 -0500
Subject: getting_started.textile: Fix another typo
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index e17b1ee1ee..e3488cee1f 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -61,7 +61,7 @@ The Rails philosophy includes several guiding principles:
* DRY - "Don't Repeat Yourself" - suggests that writing the same code over and over again is a bad thing.
* Convention Over Configuration - means that Rails makes assumptions about what you want to do and how you're going to
-d o it, rather than requiring you to specify every little thing through endless configuration files.
+do it, rather than requiring you to specify every little thing through endless configuration files.
* REST is the best pattern for web applications - organizing your application around resources and standard HTTP verbs
is the fastest way to go.
--
cgit v1.2.3
From 0fb3aa750f9980d26b1fe386c3f6cc0bd0bc23e5 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 7 Sep 2011 22:32:49 +0530
Subject: copy edit assets guide
---
railties/guides/source/asset_pipeline.textile | 38 +++++++++++++--------------
1 file changed, 19 insertions(+), 19 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index f2b93be35f..e5a08bbed5 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -95,7 +95,7 @@ When a scaffold or controller is generated for the application, Rails also gener
For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as +<%= javascript_include_tag params[:controller] %>+ or +<%= stylesheet_link_tag params[:controller] %>+.
-NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme - supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
+NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
h4. Asset Organization
@@ -164,15 +164,15 @@ Note that the closing tag cannot be of the style +-%>+.
h5. CSS and Sass
-When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, javascript, stylesheet.
+When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, JavaScript and stylesheet.
-* +image_url("rails.png")+ becomes +url(/assets/rails.png)+
+* +image_url("rails.png")+ becomes +url(/assets/rails.png)+.
* +image_path("rails.png")+ becomes +"/assets/rails.png"+.
The more generic form can also be used but the asset path and class must both be specified:
-* +asset_url("rails.png", image)+ becomes +url(/assets/rails.png)+
-* +asset_path("rails.png", image)+ becomes +"/assets/rails.png"+
+* +asset_url("rails.png", image)+ becomes +url(/assets/rails.png)+.
+* +asset_path("rails.png", image)+ becomes +"/assets/rails.png"+.
h5. JavaScript/CoffeeScript and ERB
@@ -186,7 +186,7 @@ $('#logo').attr({
This writes the path to the particular asset being referenced.
-Similary, you can use the asset_path helper in CoffeeScript files with +erb+ extension (Eg. application.js.coffee.erb):
+Similarly, you can use the +asset_path+ helper in CoffeeScript files with +erb+ extension (eg. application.js.coffee.erb):
$('#logo').attr src: "<% asset_path('logo.png') %>"
@@ -338,7 +338,7 @@ The rake task is:
bundle exec rake assets:precompile
-Capistrano (v2.8.0+) has a recipe to handle this in deployment. Add the following line to +Capfile+:
+Capistrano (v2.8.0 and above) has a recipe to handle this in deployment. Add the following line to +Capfile+:
load 'deploy/assets'
@@ -348,7 +348,7 @@ This links the folder specified in +config.assets.prefix+ to +shared/assets+. If
It is important that this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page.
-Note: If you are precompiling your assets locally you can use +bundle install --without assets+ when installing the gems on the server to avoid install of the assets gems (the gems in the assets group in the Gemfile).
+NOTE. If you are precompiling your assets locally, you can use +bundle install --without assets+ on the server to avoid installing the assets gems (the gems in the assets group in the Gemfile).
The default matcher for compiling files includes +application.js+, +application.css+ and all files that do not end in +js+ or +css+:
@@ -362,7 +362,7 @@ If you have other manifests or individual stylesheets and JavaScript files to in
config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
-The rake task also generates a +manifest.yml+ that contains a list with all your assets and their respective fingerprints. This is used by the Rails helper methods and avoids handing the mapping requests back to Sprockets. Manifest file typically look like this:
+The rake task also generates a +manifest.yml+ that contains a list with all your assets and their respective fingerprints. This is used by the Rails helper methods and avoids handing the mapping requests back to Sprockets. A typical manifest file looks like:
---
@@ -451,7 +451,15 @@ On the first request the assets are compiled and cached as outlined in developme
Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache.
-This mode uses more memory and is lower performance than the default. It is not recommended.
+This mode uses more memory, performs poorer than the default and is not recommended.
+
+When deploying a production application to a system without any pre-existing JavaScript runtimes, you may want to add one to your Gemfile:
+
+
+group :production do
+ gem 'therubyracer'
+end
+
h3. Customizing the Pipeline
@@ -481,7 +489,7 @@ config.assets.js_compressor = :uglifier
The +config.assets.compress+ must be set to +true+ to enable JavaScript compression
-NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme -- supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
+NOTE: You will need a "ExecJS":https://github.com/sstephenson/execjs#readme supported runtime in order to use +uglifier+. If you are using Mac OS X or Windows you have installed a JavaScript runtime in your operating system. Check "ExecJS":https://github.com/sstephenson/execjs#readme documentation to know all supported JavaScript runtimes.
h4. Using Your Own Compressor
@@ -608,11 +616,3 @@ group :assets do
gem 'uglifier'
end
-
-Rails 3.1 requires "execjs":https://github.com/sstephenson/execjs - but it doesn't provide a default javascript runtime. When deploying a production app to a system without a pre-existing javascript runtime, you may want to add:
-
-
-group :production do
- gem 'therubyracer'
-end
-
--
cgit v1.2.3
From 190a2bf9c482fef8412982ea31a755d7e59f17b6 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 7 Sep 2011 22:33:04 +0530
Subject: Revert "Rails.root is a Pathname, no need to use File.join first."
This reverts commit 760fd1eb42038a64591036fc5d687afc98f272aa.
Reason: We need a fully qualified path string here, not a Pathname.
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index e5a08bbed5..bad1c08747 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -112,7 +112,7 @@ All subdirectories that exist within these three locations are added to the sear
You can add additional (fully qualified) paths to the pipeline in +application.rb+. For example:
-config.assets.paths << Rails.root.join('app', 'assets', 'flash')
+config.assets.paths << File.join(Rails.root, 'app', 'assets', 'flash')
h4. Coding Links to Assets
--
cgit v1.2.3
From f50aeda2f73b47c47664e3651c638ba624418b8b Mon Sep 17 00:00:00 2001
From: dharmatech
Date: Wed, 7 Sep 2011 20:23:28 -0500
Subject: getting_started.textile section 6: Correct file names in table
---
railties/guides/source/getting_started.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index e3488cee1f..f4a61482c6 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -549,9 +549,9 @@ folders, and edit config/routes.rb. Here's a quick overview of what it
|app/views/posts/new.html.erb |A view to create a new post|
|app/views/posts/_form.html.erb |A partial to control the overall look and feel of the form used in edit and new views|
|app/helpers/posts_helper.rb |Helper functions to be used from the post views|
-|app/assets/stylesheets/scaffold.css.scss |Cascading style sheet to make the scaffolded views look better|
-|app/assets/stylesheets/post.css.scss |Cascading style sheet for the posts controller|
-|app/assets/javascripts/post.js.coffee |CoffeeScript for the posts controller|
+|app/assets/stylesheets/scaffolds.css.scss |Cascading style sheet to make the scaffolded views look better|
+|app/assets/stylesheets/posts.css.scss |Cascading style sheet for the posts controller|
+|app/assets/javascripts/posts.js.coffee |CoffeeScript for the posts controller|
|test/unit/post_test.rb |Unit testing harness for the posts model|
|test/functional/posts_controller_test.rb |Functional testing harness for the posts controller|
|test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper|
--
cgit v1.2.3
From 59198ecb657763b4fbaee84b47a74ebb99b3e54c Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 8 Sep 2011 18:25:43 +0530
Subject: some copy-edits
---
railties/guides/source/asset_pipeline.textile | 4 ++--
railties/guides/source/getting_started.textile | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index bad1c08747..ba48a2196b 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -415,12 +415,12 @@ For Apache:
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
-
+
# without these, Content-Type will be "application/x-gzip"
ForceType text/css
-
+
ForceType text/javascript
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index f4a61482c6..acd665983a 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -549,9 +549,9 @@ folders, and edit config/routes.rb. Here's a quick overview of what it
|app/views/posts/new.html.erb |A view to create a new post|
|app/views/posts/_form.html.erb |A partial to control the overall look and feel of the form used in edit and new views|
|app/helpers/posts_helper.rb |Helper functions to be used from the post views|
-|app/assets/stylesheets/scaffolds.css.scss |Cascading style sheet to make the scaffolded views look better|
-|app/assets/stylesheets/posts.css.scss |Cascading style sheet for the posts controller|
-|app/assets/javascripts/posts.js.coffee |CoffeeScript for the posts controller|
+|app/assets/stylesheets/scaffolds.css.scss |Cascading style sheet to make the scaffolded views look better|
+|app/assets/stylesheets/posts.css.scss |Cascading style sheet for the posts controller|
+|app/assets/javascripts/posts.js.coffee |CoffeeScript for the posts controller|
|test/unit/post_test.rb |Unit testing harness for the posts model|
|test/functional/posts_controller_test.rb |Functional testing harness for the posts controller|
|test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper|
--
cgit v1.2.3
From 8a0876478d1f0875a5a295bbce6b7925907dc60e Mon Sep 17 00:00:00 2001
From: Michael P Laing
Date: Sat, 10 Sep 2011 16:38:50 +0200
Subject: Update to conform to rails 3.1 generated caode
---
railties/guides/source/getting_started.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index acd665983a..1587b20c18 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -821,8 +821,8 @@ this layout in your editor and modify the +body+ tag:
Blog
- <%= stylesheet_link_tag :all %>
- <%= javascript_include_tag :defaults %>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
--
cgit v1.2.3
From e8e1911738ce990b55d068e603124572535baf5d Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Sat, 10 Sep 2011 19:29:50 +0200
Subject: clarify that documentation bugs have to be reported as Rails issues.
[Closes #2858]
---
railties/guides/source/layout.html.erb | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index 3ccbc3a477..4ef569013c 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -129,6 +129,10 @@
<%= link_to 'Ruby on Rails Guides Guidelines', 'ruby_on_rails_guides_guidelines.html' %>
for style and conventions.
+
+ If for whatever reason you spot something to fix but cannot patch it yourself, please
+ <%= link_to 'open an issue', 'https://github.com/rails/rails/issues' %>.
+
And last but not least, any kind of discussion regarding Ruby on Rails
documentation is very welcome in the <%= link_to 'rubyonrails-docs mailing list', 'http://groups.google.com/group/rubyonrails-docs' %>.
--
cgit v1.2.3
From 28e32598b9a99a2e5794e1ee8882ca42746ae513 Mon Sep 17 00:00:00 2001
From: Andy Lindeman
Date: Sat, 10 Sep 2011 21:49:13 -0400
Subject: Fix for :instance_reader => false code example
---
railties/guides/source/active_support_core_extensions.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index b2436a2e68..9e2fe2c694 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1020,7 +1020,7 @@ class A
class_attribute :x, :instance_reader => false
end
-A.x = 1 # NoMethodError
+A.new.x = 1 # NoMethodError
For convenience +class_attribute+ also defines an instance predicate which is the double negation of what the instance reader returns. In the examples above it would be called +x?+.
--
cgit v1.2.3
From 22a4f7e8bd3c70067824945881a61820aad7aff6 Mon Sep 17 00:00:00 2001
From: Emin Hasanov
Date: Sun, 11 Sep 2011 14:18:07 +0600
Subject: Fix typo in "must-revalidate" header name
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index ba48a2196b..211b02b94b 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -282,7 +282,7 @@ When debug mode is off Sprockets will concatenate and run the necessary preproce
-Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response.
+Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response.
If any of the files in the manifest have changed between requests, the server responds with a new compiled file.
--
cgit v1.2.3
From e47bb1cbe7bb33318f2ed2f1ca021ddd71f6c50f Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 11 Sep 2011 19:44:42 +0530
Subject: merged the contribution guides and changed the link in the layout
accordingly
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 10 ++++++----
railties/guides/source/layout.html.erb | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index c302d393aa..968fa7a1f1 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -257,16 +257,18 @@ h3. Contributing to the Rails Documentation
Ruby on Rails has two main sets of documentation: The guides help you to learn Ruby on Rails, and the API is a reference.
-You can create an issue in GitHub issues to fix or expand documentation. However, if you're confident about your changes you can push them yourself directly via "docrails":https://github.com/lifo/docrails/tree/master. docrails is a branch with an *open commit policy* and public write access. Commits to docrails are still reviewed, but that happens after they are pushed. docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation.
+You can help improve the Rails guides by making them more coherent, adding missing information, correcting factual errors, fixing typos, bringing it up to date with the latest edge Rails. To get involved in the translation of Rails guides, please see "Translating Rails Guides":https://wiki.github.com/lifo/docrails/translating-rails-guides.
+
+If you're confident about your changes, you can push them yourself directly via "docrails":https://github.com/lifo/docrails. docrails is a branch with an *open commit policy* and public write access. Commits to docrails are still reviewed, but that happens after they are pushed. docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation.
+
+If you are unsure of the documentation changes, you can create an issue in the "Rails":https://github.com/rails/rails repository on GitHub.
When working with documentation, please take into account the "API Documentation Guidelines":api_documentation_guidelines.html and the "Ruby on Rails Guides Guidelines":ruby_on_rails_guides_guidelines.html.
-NOTE: As explained above, ordinary code patches should have proper documentation coverage. docrails is only used for isolated documentation improvements.
+NOTE: As explained earlier, ordinary code patches should have proper documentation coverage. docrails is only used for isolated documentation improvements.
WARNING: docrails has a very strict policy: no code can be touched whatsoever, no matter how trivial or small the change. Only RDoc and guides can be edited via docrails. Also, CHANGELOGs should never be edited in docrails.
-If you have an idea for a new guide you can refer to the "contribution page":contribute.html for instructions on getting involved.
-
h3. Contributing to the Rails Code
h4. Clone the Rails Repository
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index 4ef569013c..4c979888b7 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -91,7 +91,7 @@
--
cgit v1.2.3
From 6e782f8944122e99091b38b07dcc777f02b1836c Mon Sep 17 00:00:00 2001
From: Alan Zeino
Date: Mon, 12 Sep 2011 11:12:09 +1000
Subject: Slight change to reflect current 'destroy' code generated by scaffold
in 3.1 release.
---
railties/guides/source/getting_started.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 1587b20c18..219fa5afde 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1083,8 +1083,8 @@ def destroy
@post.destroy
respond_to do |format|
- format.html { redirect_to(posts_url) }
- format.json { render :json => {}, :status => :ok }
+ format.html { redirect_to posts_url }
+ format.json { head :ok }
end
end
--
cgit v1.2.3
From d7154d483269fc25d771d5b8b7b8a2c889e4b3f5 Mon Sep 17 00:00:00 2001
From: James Gifford
Date: Mon, 12 Sep 2011 10:30:45 -0400
Subject: Added getting_started code, updated guide with link to rails github
repo and path to code
---
railties/guides/code/getting_started/Gemfile | 32 +++
railties/guides/code/getting_started/README | 261 +++++++++++++++++++++
railties/guides/code/getting_started/Rakefile | 7 +
.../getting_started/app/assets/images/rails.png | Bin 0 -> 6646 bytes
.../app/assets/javascripts/application.js | 9 +
.../app/assets/javascripts/comments.js.coffee | 3 +
.../app/assets/javascripts/home.js.coffee | 3 +
.../app/assets/javascripts/posts.js.coffee | 3 +
.../app/assets/stylesheets/application.css | 7 +
.../app/assets/stylesheets/comments.css.scss | 3 +
.../app/assets/stylesheets/home.css.scss | 3 +
.../app/assets/stylesheets/posts.css.scss | 3 +
.../app/assets/stylesheets/scaffolds.css.scss | 56 +++++
.../app/controllers/application_controller.rb | 3 +
.../app/controllers/comments_controller.rb | 16 ++
.../app/controllers/home_controller.rb | 5 +
.../app/controllers/posts_controller.rb | 84 +++++++
.../app/helpers/application_helper.rb | 2 +
.../getting_started/app/helpers/comments_helper.rb | 2 +
.../getting_started/app/helpers/home_helper.rb | 2 +
.../getting_started/app/helpers/posts_helper.rb | 5 +
.../code/getting_started/app/mailers/.gitkeep | 0
.../code/getting_started/app/models/.gitkeep | 0
.../code/getting_started/app/models/comment.rb | 3 +
.../guides/code/getting_started/app/models/post.rb | 11 +
.../guides/code/getting_started/app/models/tag.rb | 3 +
.../app/views/comments/_comment.html.erb | 15 ++
.../app/views/comments/_form.html.erb | 13 +
.../getting_started/app/views/home/index.html.erb | 2 +
.../getting_started/app/views/home/index.html.erb~ | 2 +
.../app/views/layouts/application.html.erb | 14 ++
.../getting_started/app/views/posts/_form.html.erb | 32 +++
.../getting_started/app/views/posts/edit.html.erb | 6 +
.../getting_started/app/views/posts/index.html.erb | 27 +++
.../getting_started/app/views/posts/new.html.erb | 5 +
.../getting_started/app/views/posts/show.html.erb | 31 +++
.../getting_started/app/views/tags/_form.html.erb | 12 +
railties/guides/code/getting_started/config.ru | 4 +
.../code/getting_started/config/application.rb | 48 ++++
.../guides/code/getting_started/config/boot.rb | 6 +
.../code/getting_started/config/database.yml | 25 ++
.../code/getting_started/config/environment.rb | 5 +
.../config/environments/development.rb | 30 +++
.../config/environments/production.rb | 60 +++++
.../getting_started/config/environments/test.rb | 42 ++++
.../config/initializers/backtrace_silencers.rb | 7 +
.../config/initializers/inflections.rb | 10 +
.../config/initializers/mime_types.rb | 5 +
.../config/initializers/secret_token.rb | 7 +
.../config/initializers/session_store.rb | 8 +
.../config/initializers/wrap_parameters.rb | 14 ++
.../code/getting_started/config/locales/en.yml | 5 +
.../guides/code/getting_started/config/routes.rb | 64 +++++
.../guides/code/getting_started/config/routes.rb~ | 60 +++++
.../db/migrate/20110901012504_create_posts.rb | 11 +
.../db/migrate/20110901012815_create_comments.rb | 12 +
.../db/migrate/20110901013701_create_tags.rb | 11 +
railties/guides/code/getting_started/db/schema.rb | 43 ++++
railties/guides/code/getting_started/db/seeds.rb | 7 +
.../guides/code/getting_started/doc/README_FOR_APP | 2 +
.../code/getting_started/lib/assets/.gitkeep | 0
.../guides/code/getting_started/lib/tasks/.gitkeep | 0
.../guides/code/getting_started/public/404.html | 26 ++
.../guides/code/getting_started/public/422.html | 26 ++
.../guides/code/getting_started/public/500.html | 26 ++
.../guides/code/getting_started/public/favicon.ico | 0
.../guides/code/getting_started/public/robots.txt | 5 +
railties/guides/code/getting_started/script/rails | 6 +
.../code/getting_started/test/fixtures/.gitkeep | 0
.../getting_started/test/fixtures/comments.yml | 11 +
.../code/getting_started/test/fixtures/posts.yml | 11 +
.../code/getting_started/test/fixtures/tags.yml | 9 +
.../code/getting_started/test/functional/.gitkeep | 0
.../test/functional/comments_controller_test.rb | 7 +
.../test/functional/home_controller_test.rb | 9 +
.../test/functional/posts_controller_test.rb | 49 ++++
.../code/getting_started/test/integration/.gitkeep | 0
.../test/performance/browsing_test.rb | 12 +
.../code/getting_started/test/test_helper.rb | 13 +
.../guides/code/getting_started/test/unit/.gitkeep | 0
.../code/getting_started/test/unit/comment_test.rb | 7 +
.../test/unit/helpers/comments_helper_test.rb | 4 +
.../test/unit/helpers/home_helper_test.rb | 4 +
.../test/unit/helpers/posts_helper_test.rb | 4 +
.../code/getting_started/test/unit/post_test.rb | 7 +
.../code/getting_started/test/unit/tag_test.rb | 7 +
.../vendor/assets/stylesheets/.gitkeep | 0
.../code/getting_started/vendor/plugins/.gitkeep | 0
railties/guides/source/getting_started.textile | 3 +
89 files changed, 1417 insertions(+)
create mode 100644 railties/guides/code/getting_started/Gemfile
create mode 100644 railties/guides/code/getting_started/README
create mode 100644 railties/guides/code/getting_started/Rakefile
create mode 100644 railties/guides/code/getting_started/app/assets/images/rails.png
create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/application.js
create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee
create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee
create mode 100644 railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee
create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/application.css
create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss
create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss
create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss
create mode 100644 railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss
create mode 100644 railties/guides/code/getting_started/app/controllers/application_controller.rb
create mode 100644 railties/guides/code/getting_started/app/controllers/comments_controller.rb
create mode 100644 railties/guides/code/getting_started/app/controllers/home_controller.rb
create mode 100644 railties/guides/code/getting_started/app/controllers/posts_controller.rb
create mode 100644 railties/guides/code/getting_started/app/helpers/application_helper.rb
create mode 100644 railties/guides/code/getting_started/app/helpers/comments_helper.rb
create mode 100644 railties/guides/code/getting_started/app/helpers/home_helper.rb
create mode 100644 railties/guides/code/getting_started/app/helpers/posts_helper.rb
create mode 100644 railties/guides/code/getting_started/app/mailers/.gitkeep
create mode 100644 railties/guides/code/getting_started/app/models/.gitkeep
create mode 100644 railties/guides/code/getting_started/app/models/comment.rb
create mode 100644 railties/guides/code/getting_started/app/models/post.rb
create mode 100644 railties/guides/code/getting_started/app/models/tag.rb
create mode 100644 railties/guides/code/getting_started/app/views/comments/_comment.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/comments/_form.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/home/index.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/home/index.html.erb~
create mode 100644 railties/guides/code/getting_started/app/views/layouts/application.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/posts/_form.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/posts/edit.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/posts/index.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/posts/new.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/posts/show.html.erb
create mode 100644 railties/guides/code/getting_started/app/views/tags/_form.html.erb
create mode 100644 railties/guides/code/getting_started/config.ru
create mode 100644 railties/guides/code/getting_started/config/application.rb
create mode 100644 railties/guides/code/getting_started/config/boot.rb
create mode 100644 railties/guides/code/getting_started/config/database.yml
create mode 100644 railties/guides/code/getting_started/config/environment.rb
create mode 100644 railties/guides/code/getting_started/config/environments/development.rb
create mode 100644 railties/guides/code/getting_started/config/environments/production.rb
create mode 100644 railties/guides/code/getting_started/config/environments/test.rb
create mode 100644 railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb
create mode 100644 railties/guides/code/getting_started/config/initializers/inflections.rb
create mode 100644 railties/guides/code/getting_started/config/initializers/mime_types.rb
create mode 100644 railties/guides/code/getting_started/config/initializers/secret_token.rb
create mode 100644 railties/guides/code/getting_started/config/initializers/session_store.rb
create mode 100644 railties/guides/code/getting_started/config/initializers/wrap_parameters.rb
create mode 100644 railties/guides/code/getting_started/config/locales/en.yml
create mode 100644 railties/guides/code/getting_started/config/routes.rb
create mode 100644 railties/guides/code/getting_started/config/routes.rb~
create mode 100644 railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb
create mode 100644 railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb
create mode 100644 railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb
create mode 100644 railties/guides/code/getting_started/db/schema.rb
create mode 100644 railties/guides/code/getting_started/db/seeds.rb
create mode 100644 railties/guides/code/getting_started/doc/README_FOR_APP
create mode 100644 railties/guides/code/getting_started/lib/assets/.gitkeep
create mode 100644 railties/guides/code/getting_started/lib/tasks/.gitkeep
create mode 100644 railties/guides/code/getting_started/public/404.html
create mode 100644 railties/guides/code/getting_started/public/422.html
create mode 100644 railties/guides/code/getting_started/public/500.html
create mode 100644 railties/guides/code/getting_started/public/favicon.ico
create mode 100644 railties/guides/code/getting_started/public/robots.txt
create mode 100755 railties/guides/code/getting_started/script/rails
create mode 100644 railties/guides/code/getting_started/test/fixtures/.gitkeep
create mode 100644 railties/guides/code/getting_started/test/fixtures/comments.yml
create mode 100644 railties/guides/code/getting_started/test/fixtures/posts.yml
create mode 100644 railties/guides/code/getting_started/test/fixtures/tags.yml
create mode 100644 railties/guides/code/getting_started/test/functional/.gitkeep
create mode 100644 railties/guides/code/getting_started/test/functional/comments_controller_test.rb
create mode 100644 railties/guides/code/getting_started/test/functional/home_controller_test.rb
create mode 100644 railties/guides/code/getting_started/test/functional/posts_controller_test.rb
create mode 100644 railties/guides/code/getting_started/test/integration/.gitkeep
create mode 100644 railties/guides/code/getting_started/test/performance/browsing_test.rb
create mode 100644 railties/guides/code/getting_started/test/test_helper.rb
create mode 100644 railties/guides/code/getting_started/test/unit/.gitkeep
create mode 100644 railties/guides/code/getting_started/test/unit/comment_test.rb
create mode 100644 railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb
create mode 100644 railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb
create mode 100644 railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb
create mode 100644 railties/guides/code/getting_started/test/unit/post_test.rb
create mode 100644 railties/guides/code/getting_started/test/unit/tag_test.rb
create mode 100644 railties/guides/code/getting_started/vendor/assets/stylesheets/.gitkeep
create mode 100644 railties/guides/code/getting_started/vendor/plugins/.gitkeep
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/Gemfile b/railties/guides/code/getting_started/Gemfile
new file mode 100644
index 0000000000..51774934cd
--- /dev/null
+++ b/railties/guides/code/getting_started/Gemfile
@@ -0,0 +1,32 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.0'
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', " ~> 3.1.0"
+ gem 'coffee-rails', "~> 3.1.0"
+ gem 'uglifier'
+end
+
+gem 'jquery-rails'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+group :test do
+ # Pretty printed test output
+ gem 'turn', :require => false
+end
diff --git a/railties/guides/code/getting_started/README b/railties/guides/code/getting_started/README
new file mode 100644
index 0000000000..7c36f2356e
--- /dev/null
+++ b/railties/guides/code/getting_started/README
@@ -0,0 +1,261 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb"
+templates that are primarily responsible for inserting pre-built data in between
+HTML tags. The model contains the "smart" domain objects (such as Account,
+Product, Person, Post) that holds all the business logic and knows how to
+persist themselves to a database. The controller handles the incoming requests
+(such as Save New Account, Update Product, Show Post) by manipulating the model
+and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, create a new Rails application:
+ rails new myapp (where myapp is the application name)
+
+2. Change directory to myapp and start the web server:
+ cd myapp; rails server (run with --help for options)
+
+3. Go to http://localhost:3000/ and you'll see:
+ "Welcome aboard: You're riding Ruby on Rails!"
+
+4. Follow the guidelines to start developing your application. You can find
+the following resources handy:
+
+* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
+* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files. Have "tail -f" commands
+running on the server.log and development.log. Rails will automatically display
+debugging and runtime information to these files. Debugging info will also be
+shown in the browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code
+using the Ruby logger class from inside your controllers. Example:
+
+ class WeblogController < ActionController::Base
+ def destroy
+ @weblog = Weblog.find(params[:id])
+ @weblog.destroy
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+ end
+ end
+
+The result will be a message in your log file along the lines of:
+
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
+several books available online as well:
+
+* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two books will bring you up to speed on the Ruby language and also on
+programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your
+Mongrel or WEBrick server with --debugger. This means that you can break out of
+execution at any point in the code, investigate and change the model, and then,
+resume execution! You need to install ruby-debug to run the server in debugging
+mode. With gems, use sudo gem install ruby-debug. Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.all
+ debugger
+ end
+ end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+ >> @posts.inspect
+ => "[#nil, "body"=>nil, "id"=>"1"}>,
+ #"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better, you can examine how your runtime objects actually work:
+
+ >> f = @posts.first
+ => #nil, "body"=>nil, "id"=>"1"}>
+ >> f.
+ Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you can enter "cont".
+
+
+== Console
+
+The console is a Ruby shell, which allows you to interact with your
+application's domain model. Here you'll have all parts of the application
+configured, just like it is when the application is running. You can inspect
+domain models, change values, and save to the database. Starting the script
+without arguments will launch it in the development environment.
+
+To start the console, run rails console from the application
+directory.
+
+Options:
+
+* Passing the -s, --sandbox argument will rollback any modifications
+ made to the database.
+* Passing an environment name as an argument will load the corresponding
+ environment. Example: rails console production.
+
+To reload your controllers and models after launching the console run
+reload!
+
+More information about irb can be found at:
+link:http://www.rubycentral.org/pickaxe/irb.html
+
+
+== dbconsole
+
+You can go to the command line of your database directly through rails
+dbconsole. You would be connected to the database with the credentials
+defined in database.yml. Starting the script without arguments will connect you
+to the development database. Passing an argument will connect you to a different
+database, like rails dbconsole production. Currently works for MySQL,
+PostgreSQL and SQLite 3.
+
+== Description of Contents
+
+The default directory structure of a generated Ruby on Rails application:
+
+ |-- app
+ | |-- assets
+ | |-- images
+ | |-- javascripts
+ | `-- stylesheets
+ | |-- controllers
+ | |-- helpers
+ | |-- mailers
+ | |-- models
+ | `-- views
+ | `-- layouts
+ |-- config
+ | |-- environments
+ | |-- initializers
+ | `-- locales
+ |-- db
+ |-- doc
+ |-- lib
+ | `-- tasks
+ |-- log
+ |-- public
+ |-- script
+ |-- test
+ | |-- fixtures
+ | |-- functional
+ | |-- integration
+ | |-- performance
+ | `-- unit
+ |-- tmp
+ | |-- cache
+ | |-- pids
+ | |-- sessions
+ | `-- sockets
+ `-- vendor
+ |-- assets
+ `-- stylesheets
+ `-- plugins
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/assets
+ Contains subdirectories for images, stylesheets, and JavaScript files.
+
+app/controllers
+ Holds controllers that should be named like weblogs_controller.rb for
+ automated URL mapping. All controllers should descend from
+ ApplicationController which itself descends from ActionController::Base.
+
+app/models
+ Holds models that should be named like post.rb. Models descend from
+ ActiveRecord::Base by default.
+
+app/views
+ Holds the template files for the view that should be named like
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
+ eRuby syntax by default.
+
+app/views/layouts
+ Holds the template files for layouts to be used with views. This models the
+ common header/footer method of wrapping views. In your views, define a layout
+ using the layout :default and create a file named default.html.erb.
+ Inside default.html.erb, call <% yield %> to render the view using this
+ layout.
+
+app/helpers
+ Holds view helpers that should be named like weblogs_helper.rb. These are
+ generated for you automatically when using generators for controllers.
+ Helpers can be used to wrap functionality for your views into methods.
+
+config
+ Configuration files for the Rails environment, the routing map, the database,
+ and other dependencies.
+
+db
+ Contains the database schema in schema.rb. db/migrate contains all the
+ sequence of Migrations for your schema.
+
+doc
+ This directory is where your application documentation will be stored when
+ generated using rake doc:app
+
+lib
+ Application specific libraries. Basically, any kind of custom code that
+ doesn't belong under controllers, models, or helpers. This directory is in
+ the load path.
+
+public
+ The directory available for the web server. Also contains the dispatchers and the
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
+ server.
+
+script
+ Helper scripts for automation and generation.
+
+test
+ Unit and functional tests along with fixtures. When using the rails generate
+ command, template test files will be generated for you and placed in this
+ directory.
+
+vendor
+ External libraries that the application depends on. Also includes the plugins
+ subdirectory. If the app has frozen rails, those gems also go here, under
+ vendor/rails/. This directory is in the load path.
diff --git a/railties/guides/code/getting_started/Rakefile b/railties/guides/code/getting_started/Rakefile
new file mode 100644
index 0000000000..e1d1ec8615
--- /dev/null
+++ b/railties/guides/code/getting_started/Rakefile
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+Blog::Application.load_tasks
diff --git a/railties/guides/code/getting_started/app/assets/images/rails.png b/railties/guides/code/getting_started/app/assets/images/rails.png
new file mode 100644
index 0000000000..d5edc04e65
Binary files /dev/null and b/railties/guides/code/getting_started/app/assets/images/rails.png differ
diff --git a/railties/guides/code/getting_started/app/assets/javascripts/application.js b/railties/guides/code/getting_started/app/assets/javascripts/application.js
new file mode 100644
index 0000000000..37c7bfcdb5
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/javascripts/application.js
@@ -0,0 +1,9 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
diff --git a/railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee b/railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee
new file mode 100644
index 0000000000..761567942f
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/javascripts/comments.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee b/railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee
new file mode 100644
index 0000000000..761567942f
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/javascripts/home.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee b/railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee
new file mode 100644
index 0000000000..761567942f
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/javascripts/posts.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/application.css b/railties/guides/code/getting_started/app/assets/stylesheets/application.css
new file mode 100644
index 0000000000..fc25b5723f
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/stylesheets/application.css
@@ -0,0 +1,7 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require_self
+ *= require_tree .
+*/
\ No newline at end of file
diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss
new file mode 100644
index 0000000000..e730912783
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/stylesheets/comments.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Comments controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss
new file mode 100644
index 0000000000..f0ddc6846a
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/stylesheets/home.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the home controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss
new file mode 100644
index 0000000000..ed4dfd10f2
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/stylesheets/posts.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Posts controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss b/railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss
new file mode 100644
index 0000000000..05188f08ed
--- /dev/null
+++ b/railties/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
diff --git a/railties/guides/code/getting_started/app/controllers/application_controller.rb b/railties/guides/code/getting_started/app/controllers/application_controller.rb
new file mode 100644
index 0000000000..e8065d9505
--- /dev/null
+++ b/railties/guides/code/getting_started/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
diff --git a/railties/guides/code/getting_started/app/controllers/comments_controller.rb b/railties/guides/code/getting_started/app/controllers/comments_controller.rb
new file mode 100644
index 0000000000..7447fd078b
--- /dev/null
+++ b/railties/guides/code/getting_started/app/controllers/comments_controller.rb
@@ -0,0 +1,16 @@
+class CommentsController < ApplicationController
+ http_basic_authenticate_with :name => "dhh", :password => "secret", :only => :destroy
+ def create
+ @post = Post.find(params[:post_id])
+ @comment = @post.comments.create(params[:comment])
+ redirect_to post_path(@post)
+ end
+
+ def destroy
+ @post = Post.find(params[:post_id])
+ @comment = @post.comments.find(params[:id])
+ @comment.destroy
+ redirect_to post_path(@post)
+ end
+
+end
diff --git a/railties/guides/code/getting_started/app/controllers/home_controller.rb b/railties/guides/code/getting_started/app/controllers/home_controller.rb
new file mode 100644
index 0000000000..6cc31c1ca3
--- /dev/null
+++ b/railties/guides/code/getting_started/app/controllers/home_controller.rb
@@ -0,0 +1,5 @@
+class HomeController < ApplicationController
+ def index
+ end
+
+end
diff --git a/railties/guides/code/getting_started/app/controllers/posts_controller.rb b/railties/guides/code/getting_started/app/controllers/posts_controller.rb
new file mode 100644
index 0000000000..7e903c984c
--- /dev/null
+++ b/railties/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -0,0 +1,84 @@
+class PostsController < ApplicationController
+ http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
+ # GET /posts
+ # GET /posts.json
+ def index
+ @posts = Post.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @posts }
+ end
+ end
+
+ # GET /posts/1
+ # GET /posts/1.json
+ def show
+ @post = Post.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @post }
+ end
+ end
+
+ # GET /posts/new
+ # GET /posts/new.json
+ def new
+ @post = Post.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @post }
+ end
+ end
+
+ # GET /posts/1/edit
+ def edit
+ @post = Post.find(params[:id])
+ end
+
+ # POST /posts
+ # POST /posts.json
+ def create
+ @post = Post.new(params[:post])
+
+ respond_to do |format|
+ if @post.save
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
+ format.json { render json: @post, status: :created, location: @post }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /posts/1
+ # PUT /posts/1.json
+ def update
+ @post = Post.find(params[:id])
+
+ respond_to do |format|
+ if @post.update_attributes(params[:post])
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /posts/1
+ # DELETE /posts/1.json
+ def destroy
+ @post = Post.find(params[:id])
+ @post.destroy
+
+ respond_to do |format|
+ format.html { redirect_to posts_url }
+ format.json { head :ok }
+ end
+ end
+end
diff --git a/railties/guides/code/getting_started/app/helpers/application_helper.rb b/railties/guides/code/getting_started/app/helpers/application_helper.rb
new file mode 100644
index 0000000000..de6be7945c
--- /dev/null
+++ b/railties/guides/code/getting_started/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
diff --git a/railties/guides/code/getting_started/app/helpers/comments_helper.rb b/railties/guides/code/getting_started/app/helpers/comments_helper.rb
new file mode 100644
index 0000000000..0ec9ca5f2d
--- /dev/null
+++ b/railties/guides/code/getting_started/app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
diff --git a/railties/guides/code/getting_started/app/helpers/home_helper.rb b/railties/guides/code/getting_started/app/helpers/home_helper.rb
new file mode 100644
index 0000000000..23de56ac60
--- /dev/null
+++ b/railties/guides/code/getting_started/app/helpers/home_helper.rb
@@ -0,0 +1,2 @@
+module HomeHelper
+end
diff --git a/railties/guides/code/getting_started/app/helpers/posts_helper.rb b/railties/guides/code/getting_started/app/helpers/posts_helper.rb
new file mode 100644
index 0000000000..b6e8e67894
--- /dev/null
+++ b/railties/guides/code/getting_started/app/helpers/posts_helper.rb
@@ -0,0 +1,5 @@
+module PostsHelper
+ def join_tags(post)
+ post.tags.map { |t| t.name }.join(", ")
+ end
+end
diff --git a/railties/guides/code/getting_started/app/mailers/.gitkeep b/railties/guides/code/getting_started/app/mailers/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/app/models/.gitkeep b/railties/guides/code/getting_started/app/models/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/app/models/comment.rb b/railties/guides/code/getting_started/app/models/comment.rb
new file mode 100644
index 0000000000..4e76c5b5b0
--- /dev/null
+++ b/railties/guides/code/getting_started/app/models/comment.rb
@@ -0,0 +1,3 @@
+class Comment < ActiveRecord::Base
+ belongs_to :post
+end
diff --git a/railties/guides/code/getting_started/app/models/post.rb b/railties/guides/code/getting_started/app/models/post.rb
new file mode 100644
index 0000000000..61c2b5ae44
--- /dev/null
+++ b/railties/guides/code/getting_started/app/models/post.rb
@@ -0,0 +1,11 @@
+class Post < ActiveRecord::Base
+ validates :name, :presence => true
+ validates :title, :presence => true,
+ :length => { :minimum => 5 }
+
+ has_many :comments, :dependent => :destroy
+ has_many :tags
+
+ accepts_nested_attributes_for :tags, :allow_destroy => :true,
+ :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
+end
diff --git a/railties/guides/code/getting_started/app/models/tag.rb b/railties/guides/code/getting_started/app/models/tag.rb
new file mode 100644
index 0000000000..30992e8ba9
--- /dev/null
+++ b/railties/guides/code/getting_started/app/models/tag.rb
@@ -0,0 +1,3 @@
+class Tag < ActiveRecord::Base
+ belongs_to :post
+end
diff --git a/railties/guides/code/getting_started/app/views/comments/_comment.html.erb b/railties/guides/code/getting_started/app/views/comments/_comment.html.erb
new file mode 100644
index 0000000000..4c3fbf26cd
--- /dev/null
+++ b/railties/guides/code/getting_started/app/views/comments/_comment.html.erb
@@ -0,0 +1,15 @@
+
+ <% end %>
+<% end %>
diff --git a/railties/guides/code/getting_started/config.ru b/railties/guides/code/getting_started/config.ru
new file mode 100644
index 0000000000..ddf869e921
--- /dev/null
+++ b/railties/guides/code/getting_started/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Blog::Application
diff --git a/railties/guides/code/getting_started/config/application.rb b/railties/guides/code/getting_started/config/application.rb
new file mode 100644
index 0000000000..e914b5a80e
--- /dev/null
+++ b/railties/guides/code/getting_started/config/application.rb
@@ -0,0 +1,48 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require *Rails.groups(:assets => %w(development test))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+module Blog
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
+ end
+end
diff --git a/railties/guides/code/getting_started/config/boot.rb b/railties/guides/code/getting_started/config/boot.rb
new file mode 100644
index 0000000000..4489e58688
--- /dev/null
+++ b/railties/guides/code/getting_started/config/boot.rb
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
diff --git a/railties/guides/code/getting_started/config/database.yml b/railties/guides/code/getting_started/config/database.yml
new file mode 100644
index 0000000000..51a4dd459d
--- /dev/null
+++ b/railties/guides/code/getting_started/config/database.yml
@@ -0,0 +1,25 @@
+# SQLite version 3.x
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem 'sqlite3'
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
diff --git a/railties/guides/code/getting_started/config/environment.rb b/railties/guides/code/getting_started/config/environment.rb
new file mode 100644
index 0000000000..8f728b7ce7
--- /dev/null
+++ b/railties/guides/code/getting_started/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Blog::Application.initialize!
diff --git a/railties/guides/code/getting_started/config/environments/development.rb b/railties/guides/code/getting_started/config/environments/development.rb
new file mode 100644
index 0000000000..89932bf19b
--- /dev/null
+++ b/railties/guides/code/getting_started/config/environments/development.rb
@@ -0,0 +1,30 @@
+Blog::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+end
diff --git a/railties/guides/code/getting_started/config/environments/production.rb b/railties/guides/code/getting_started/config/environments/production.rb
new file mode 100644
index 0000000000..6ab63d30a6
--- /dev/null
+++ b/railties/guides/code/getting_started/config/environments/production.rb
@@ -0,0 +1,60 @@
+Blog::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Disable Rails's static asset server (Apache or nginx will already do this)
+ config.serve_static_assets = false
+
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Don't fallback to assets pipeline if a precompiled asset is missed
+ config.assets.compile = false
+
+ # Generate digests for assets URLs
+ config.assets.digest = true
+
+ # Defaults to Rails.root.join("public/assets")
+ # config.assets.manifest = YOUR_PATH
+
+ # Specifies the header that your server uses for sending files
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+ # config.assets.precompile += %w( search.js )
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
diff --git a/railties/guides/code/getting_started/config/environments/test.rb b/railties/guides/code/getting_started/config/environments/test.rb
new file mode 100644
index 0000000000..833241ace3
--- /dev/null
+++ b/railties/guides/code/getting_started/config/environments/test.rb
@@ -0,0 +1,42 @@
+Blog::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Configure static asset server for tests with Cache-Control for performance
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # Log error messages when you accidentally call methods on nil
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+
+ # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
+ config.assets.allow_debugging = true
+end
diff --git a/railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb b/railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000000..59385cdf37
--- /dev/null
+++ b/railties/guides/code/getting_started/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/railties/guides/code/getting_started/config/initializers/inflections.rb b/railties/guides/code/getting_started/config/initializers/inflections.rb
new file mode 100644
index 0000000000..9e8b0131f8
--- /dev/null
+++ b/railties/guides/code/getting_started/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
diff --git a/railties/guides/code/getting_started/config/initializers/mime_types.rb b/railties/guides/code/getting_started/config/initializers/mime_types.rb
new file mode 100644
index 0000000000..72aca7e441
--- /dev/null
+++ b/railties/guides/code/getting_started/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
diff --git a/railties/guides/code/getting_started/config/initializers/secret_token.rb b/railties/guides/code/getting_started/config/initializers/secret_token.rb
new file mode 100644
index 0000000000..b0c8ee23c1
--- /dev/null
+++ b/railties/guides/code/getting_started/config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Blog::Application.config.secret_token = '685a9bf865b728c6549a191c90851c1b5ec41ecb60b9e94ad79dd3f824749798aa7b5e94431901960bee57809db0947b481570f7f13376b7ca190fa28099c459'
diff --git a/railties/guides/code/getting_started/config/initializers/session_store.rb b/railties/guides/code/getting_started/config/initializers/session_store.rb
new file mode 100644
index 0000000000..1a67af58b5
--- /dev/null
+++ b/railties/guides/code/getting_started/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Blog::Application.config.session_store :cookie_store, key: '_blog_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rails generate session_migration")
+# Blog::Application.config.session_store :active_record_store
diff --git a/railties/guides/code/getting_started/config/initializers/wrap_parameters.rb b/railties/guides/code/getting_started/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000000..999df20181
--- /dev/null
+++ b/railties/guides/code/getting_started/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# Disable root element in JSON by default.
+ActiveSupport.on_load(:active_record) do
+ self.include_root_in_json = false
+end
diff --git a/railties/guides/code/getting_started/config/locales/en.yml b/railties/guides/code/getting_started/config/locales/en.yml
new file mode 100644
index 0000000000..179c14ca52
--- /dev/null
+++ b/railties/guides/code/getting_started/config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
diff --git a/railties/guides/code/getting_started/config/routes.rb b/railties/guides/code/getting_started/config/routes.rb
new file mode 100644
index 0000000000..31f0d210db
--- /dev/null
+++ b/railties/guides/code/getting_started/config/routes.rb
@@ -0,0 +1,64 @@
+Blog::Application.routes.draw do
+ resources :posts do
+ resources :comments
+ end
+
+ get "home/index"
+
+ # The priority is based upon order of creation:
+ # first created -> highest priority.
+
+ # Sample of regular route:
+ # match 'products/:id' => 'catalog#view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # resources :products
+
+ # Sample resource route with options:
+ # resources :products do
+ # member do
+ # get 'short'
+ # post 'toggle'
+ # end
+ #
+ # collection do
+ # get 'sold'
+ # end
+ # end
+
+ # Sample resource route with sub-resources:
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
+ # Sample resource route with more complex sub-resources
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get 'recent', :on => :collection
+ # end
+ # end
+
+ # Sample resource route within a namespace:
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
+ # end
+
+ # You can have the root of your site routed with "root"
+ # just remember to delete public/index.html.
+ root :to => "home#index"
+
+ # See how all your routes lay out with "rake routes"
+
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
+ # Note: This route will make all actions in every controller accessible via GET requests.
+ # match ':controller(/:action(/:id(.:format)))'
+end
diff --git a/railties/guides/code/getting_started/config/routes.rb~ b/railties/guides/code/getting_started/config/routes.rb~
new file mode 100644
index 0000000000..3d9628b55e
--- /dev/null
+++ b/railties/guides/code/getting_started/config/routes.rb~
@@ -0,0 +1,60 @@
+Blog::Application.routes.draw do
+ get "home/index"
+
+ # The priority is based upon order of creation:
+ # first created -> highest priority.
+
+ # Sample of regular route:
+ # match 'products/:id' => 'catalog#view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # resources :products
+
+ # Sample resource route with options:
+ # resources :products do
+ # member do
+ # get 'short'
+ # post 'toggle'
+ # end
+ #
+ # collection do
+ # get 'sold'
+ # end
+ # end
+
+ # Sample resource route with sub-resources:
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
+ # Sample resource route with more complex sub-resources
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get 'recent', :on => :collection
+ # end
+ # end
+
+ # Sample resource route within a namespace:
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
+ # end
+
+ # You can have the root of your site routed with "root"
+ # just remember to delete public/index.html.
+ # root :to => 'welcome#index'
+
+ # See how all your routes lay out with "rake routes"
+
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
+ # Note: This route will make all actions in every controller accessible via GET requests.
+ # match ':controller(/:action(/:id(.:format)))'
+end
diff --git a/railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb b/railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb
new file mode 100644
index 0000000000..d45a961523
--- /dev/null
+++ b/railties/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb
@@ -0,0 +1,11 @@
+class CreatePosts < ActiveRecord::Migration
+ def change
+ create_table :posts do |t|
+ t.string :name
+ t.string :title
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
diff --git a/railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb b/railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb
new file mode 100644
index 0000000000..adda8078c1
--- /dev/null
+++ b/railties/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb
@@ -0,0 +1,12 @@
+class CreateComments < ActiveRecord::Migration
+ def change
+ create_table :comments do |t|
+ t.string :commenter
+ t.text :body
+ t.references :post
+
+ t.timestamps
+ end
+ add_index :comments, :post_id
+ end
+end
diff --git a/railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb b/railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb
new file mode 100644
index 0000000000..cf95b1c3d0
--- /dev/null
+++ b/railties/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb
@@ -0,0 +1,11 @@
+class CreateTags < ActiveRecord::Migration
+ def change
+ create_table :tags do |t|
+ t.string :name
+ t.references :post
+
+ t.timestamps
+ end
+ add_index :tags, :post_id
+ end
+end
diff --git a/railties/guides/code/getting_started/db/schema.rb b/railties/guides/code/getting_started/db/schema.rb
new file mode 100644
index 0000000000..9db4fbe4b6
--- /dev/null
+++ b/railties/guides/code/getting_started/db/schema.rb
@@ -0,0 +1,43 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20110901013701) do
+
+ create_table "comments", :force => true do |t|
+ t.string "commenter"
+ t.text "body"
+ t.integer "post_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "comments", ["post_id"], :name => "index_comments_on_post_id"
+
+ create_table "posts", :force => true do |t|
+ t.string "name"
+ t.string "title"
+ t.text "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "tags", :force => true do |t|
+ t.string "name"
+ t.integer "post_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "tags", ["post_id"], :name => "index_tags_on_post_id"
+
+end
diff --git a/railties/guides/code/getting_started/db/seeds.rb b/railties/guides/code/getting_started/db/seeds.rb
new file mode 100644
index 0000000000..4edb1e857e
--- /dev/null
+++ b/railties/guides/code/getting_started/db/seeds.rb
@@ -0,0 +1,7 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
+# Mayor.create(name: 'Emanuel', city: cities.first)
diff --git a/railties/guides/code/getting_started/doc/README_FOR_APP b/railties/guides/code/getting_started/doc/README_FOR_APP
new file mode 100644
index 0000000000..fe41f5cc24
--- /dev/null
+++ b/railties/guides/code/getting_started/doc/README_FOR_APP
@@ -0,0 +1,2 @@
+Use this README file to introduce your application and point to useful places in the API for learning more.
+Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
diff --git a/railties/guides/code/getting_started/lib/assets/.gitkeep b/railties/guides/code/getting_started/lib/assets/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/lib/tasks/.gitkeep b/railties/guides/code/getting_started/lib/tasks/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/public/404.html b/railties/guides/code/getting_started/public/404.html
new file mode 100644
index 0000000000..9a48320a5f
--- /dev/null
+++ b/railties/guides/code/getting_started/public/404.html
@@ -0,0 +1,26 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
+
diff --git a/railties/guides/code/getting_started/public/422.html b/railties/guides/code/getting_started/public/422.html
new file mode 100644
index 0000000000..83660ab187
--- /dev/null
+++ b/railties/guides/code/getting_started/public/422.html
@@ -0,0 +1,26 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
+
diff --git a/railties/guides/code/getting_started/public/500.html b/railties/guides/code/getting_started/public/500.html
new file mode 100644
index 0000000000..b80307fc16
--- /dev/null
+++ b/railties/guides/code/getting_started/public/500.html
@@ -0,0 +1,26 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
We've been notified about this issue and we'll take a look at it shortly.
+
+
+
diff --git a/railties/guides/code/getting_started/public/favicon.ico b/railties/guides/code/getting_started/public/favicon.ico
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/public/robots.txt b/railties/guides/code/getting_started/public/robots.txt
new file mode 100644
index 0000000000..085187fa58
--- /dev/null
+++ b/railties/guides/code/getting_started/public/robots.txt
@@ -0,0 +1,5 @@
+# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
+#
+# To ban all spiders from the entire site uncomment the next two lines:
+# User-Agent: *
+# Disallow: /
diff --git a/railties/guides/code/getting_started/script/rails b/railties/guides/code/getting_started/script/rails
new file mode 100755
index 0000000000..f8da2cffd4
--- /dev/null
+++ b/railties/guides/code/getting_started/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
diff --git a/railties/guides/code/getting_started/test/fixtures/.gitkeep b/railties/guides/code/getting_started/test/fixtures/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/test/fixtures/comments.yml b/railties/guides/code/getting_started/test/fixtures/comments.yml
new file mode 100644
index 0000000000..d33da386bf
--- /dev/null
+++ b/railties/guides/code/getting_started/test/fixtures/comments.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ commenter: MyString
+ body: MyText
+ post:
+
+two:
+ commenter: MyString
+ body: MyText
+ post:
diff --git a/railties/guides/code/getting_started/test/fixtures/posts.yml b/railties/guides/code/getting_started/test/fixtures/posts.yml
new file mode 100644
index 0000000000..8b0f75a33d
--- /dev/null
+++ b/railties/guides/code/getting_started/test/fixtures/posts.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+ title: MyString
+ content: MyText
+
+two:
+ name: MyString
+ title: MyString
+ content: MyText
diff --git a/railties/guides/code/getting_started/test/fixtures/tags.yml b/railties/guides/code/getting_started/test/fixtures/tags.yml
new file mode 100644
index 0000000000..8485668908
--- /dev/null
+++ b/railties/guides/code/getting_started/test/fixtures/tags.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+ post:
+
+two:
+ name: MyString
+ post:
diff --git a/railties/guides/code/getting_started/test/functional/.gitkeep b/railties/guides/code/getting_started/test/functional/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/test/functional/comments_controller_test.rb b/railties/guides/code/getting_started/test/functional/comments_controller_test.rb
new file mode 100644
index 0000000000..2ec71b4ec5
--- /dev/null
+++ b/railties/guides/code/getting_started/test/functional/comments_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CommentsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/railties/guides/code/getting_started/test/functional/home_controller_test.rb b/railties/guides/code/getting_started/test/functional/home_controller_test.rb
new file mode 100644
index 0000000000..0d9bb47c3e
--- /dev/null
+++ b/railties/guides/code/getting_started/test/functional/home_controller_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class HomeControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ end
+
+end
diff --git a/railties/guides/code/getting_started/test/functional/posts_controller_test.rb b/railties/guides/code/getting_started/test/functional/posts_controller_test.rb
new file mode 100644
index 0000000000..b8f7b07820
--- /dev/null
+++ b/railties/guides/code/getting_started/test/functional/posts_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class PostsControllerTest < ActionController::TestCase
+ setup do
+ @post = posts(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:posts)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create post" do
+ assert_difference('Post.count') do
+ post :create, post: @post.attributes
+ end
+
+ assert_redirected_to post_path(assigns(:post))
+ end
+
+ test "should show post" do
+ get :show, id: @post.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @post.to_param
+ assert_response :success
+ end
+
+ test "should update post" do
+ put :update, id: @post.to_param, post: @post.attributes
+ assert_redirected_to post_path(assigns(:post))
+ end
+
+ test "should destroy post" do
+ assert_difference('Post.count', -1) do
+ delete :destroy, id: @post.to_param
+ end
+
+ assert_redirected_to posts_path
+ end
+end
diff --git a/railties/guides/code/getting_started/test/integration/.gitkeep b/railties/guides/code/getting_started/test/integration/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/test/performance/browsing_test.rb b/railties/guides/code/getting_started/test/performance/browsing_test.rb
new file mode 100644
index 0000000000..3fea27b916
--- /dev/null
+++ b/railties/guides/code/getting_started/test/performance/browsing_test.rb
@@ -0,0 +1,12 @@
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class BrowsingTest < ActionDispatch::PerformanceTest
+ # Refer to the documentation for all available options
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
+ # :output => 'tmp/performance', :formats => [:flat] }
+
+ def test_homepage
+ get '/'
+ end
+end
diff --git a/railties/guides/code/getting_started/test/test_helper.rb b/railties/guides/code/getting_started/test/test_helper.rb
new file mode 100644
index 0000000000..8bf1192ffe
--- /dev/null
+++ b/railties/guides/code/getting_started/test/test_helper.rb
@@ -0,0 +1,13 @@
+ENV["RAILS_ENV"] = "test"
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/test_help'
+
+class ActiveSupport::TestCase
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+end
diff --git a/railties/guides/code/getting_started/test/unit/.gitkeep b/railties/guides/code/getting_started/test/unit/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/test/unit/comment_test.rb b/railties/guides/code/getting_started/test/unit/comment_test.rb
new file mode 100644
index 0000000000..b6d6131a96
--- /dev/null
+++ b/railties/guides/code/getting_started/test/unit/comment_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CommentTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb b/railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb
new file mode 100644
index 0000000000..2518c16bd5
--- /dev/null
+++ b/railties/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class CommentsHelperTest < ActionView::TestCase
+end
diff --git a/railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb b/railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb
new file mode 100644
index 0000000000..4740a18dac
--- /dev/null
+++ b/railties/guides/code/getting_started/test/unit/helpers/home_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class HomeHelperTest < ActionView::TestCase
+end
diff --git a/railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb b/railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb
new file mode 100644
index 0000000000..48549c2ea1
--- /dev/null
+++ b/railties/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PostsHelperTest < ActionView::TestCase
+end
diff --git a/railties/guides/code/getting_started/test/unit/post_test.rb b/railties/guides/code/getting_started/test/unit/post_test.rb
new file mode 100644
index 0000000000..6d9d463a71
--- /dev/null
+++ b/railties/guides/code/getting_started/test/unit/post_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PostTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/railties/guides/code/getting_started/test/unit/tag_test.rb b/railties/guides/code/getting_started/test/unit/tag_test.rb
new file mode 100644
index 0000000000..b8498a117c
--- /dev/null
+++ b/railties/guides/code/getting_started/test/unit/tag_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class TagTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/railties/guides/code/getting_started/vendor/assets/stylesheets/.gitkeep b/railties/guides/code/getting_started/vendor/assets/stylesheets/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/code/getting_started/vendor/plugins/.gitkeep b/railties/guides/code/getting_started/vendor/plugins/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 1587b20c18..e1bc56823a 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -41,6 +41,9 @@ internet for learning Ruby, including:
* "Programming Ruby":http://www.ruby-doc.org/docs/ProgrammingRuby/
* "Why's (Poignant) Guide to Ruby":http://mislav.uniqpath.com/poignant-guide/
+Also, the example code for this guide is available in the rails github:https://github.com/rails/rails repository
+in rails/railties/guides/code/getting_started.
+
h3. What is Rails?
Rails is a web application development framework written in the Ruby language.
--
cgit v1.2.3
From 70198fdb3614ef0299e848440df62d18b46a7f77 Mon Sep 17 00:00:00 2001
From: dharmatech
Date: Mon, 12 Sep 2011 12:05:15 -0500
Subject: getting_started.textile: Fix typos in section "Rendering a Partial
Form"
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 1587b20c18..ae9a689678 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1453,7 +1453,7 @@ comment to a local variable named the same as the partial, in this case
h4. Rendering a Partial Form
-Lets also move that new comment section out to it's own partial, again, you
+Let's also move that new comment section out to its own partial. Again, you
create a file +app/views/comments/_form.html.erb+ and in it you put:
--
cgit v1.2.3
From c5118f29dee30d6c806c486698f3aa6ba8af919b Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Mon, 12 Sep 2011 23:24:14 +0530
Subject: change GH issue tracker url
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 968fa7a1f1..90eab150a1 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -261,7 +261,7 @@ You can help improve the Rails guides by making them more coherent, adding missi
If you're confident about your changes, you can push them yourself directly via "docrails":https://github.com/lifo/docrails. docrails is a branch with an *open commit policy* and public write access. Commits to docrails are still reviewed, but that happens after they are pushed. docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation.
-If you are unsure of the documentation changes, you can create an issue in the "Rails":https://github.com/rails/rails repository on GitHub.
+If you are unsure of the documentation changes, you can create an issue in the "Rails":https://github.com/rails/rails/issues issues tracker on GitHub.
When working with documentation, please take into account the "API Documentation Guidelines":api_documentation_guidelines.html and the "Ruby on Rails Guides Guidelines":ruby_on_rails_guides_guidelines.html.
--
cgit v1.2.3
From acc6252cb0250df8d5554fee94b0aa6dc87b32e7 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Mon, 12 Sep 2011 23:25:33 +0530
Subject: Delete contribute.textile now that its contents are merged to the
contributing_to_ruby_on_rails guide
---
railties/guides/source/contribute.textile | 70 -------------------------------
1 file changed, 70 deletions(-)
delete mode 100644 railties/guides/source/contribute.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile
deleted file mode 100644
index f9bb80861c..0000000000
--- a/railties/guides/source/contribute.textile
+++ /dev/null
@@ -1,70 +0,0 @@
-h2. Contribute to the Rails Guides
-
-Rails Guides aim to improve the Rails documentation and to make the barrier to entry as low as possible. A reasonably experienced developer should be able to use the guides to come up to speed on Rails quickly. Our sponsors have contributed prizes for those who write an entire guide, but there are many other ways to contribute.
-
-endprologue.
-
-h3. How to Contribute?
-
-* We have an open commit policy: anyone is welcome to contribute and to review contributions.
-* "docrails is hosted on GitHub":https://github.com/lifo/docrails and has public write access.
-* Guides are written in Textile, and reside at +railties/guides/source+ in the docrails project.
-* Follow the "Rails Guides Conventions":https://wiki.github.com/lifo/docrails/rails-guides-conventions.
-* Assets are stored in the +railties/guides/assets+ directory.
-* Sample format : "Active Record Associations":https://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile.
-* Sample output : "Active Record Associations":association_basics.html.
-* You can build the Guides during testing by running +bundle exec rake generate_guides+ in the +railties+ directory.
-* You're encouraged to validate XHTML for the generated guides before committing your changes by running +bundle exec rake validate_guides+ in the +railties+ directory.
-* Edge guides "can be consulted online":http://edgeguides.rubyonrails.org/. That website is generated periodically from docrails.
-
-h3. What to Contribute?
-
-* We need authors, editors, proofreaders, and translators. Adding a single paragraph of quality content to a guide is a good way to get started.
-* The easiest way to start is by improving an existing guide:
-** Improve the structure to make it more coherent.
-** Add missing information.
-** Correct any factual errors.
-** Fix typos or improve style.
-** Bring it up to date with the latest Edge Rails.
-* We're also open to suggestions for entire new guides:
-** Contact lifo or fxn to get your idea approved. See the Contact section below.
-** If you're the main author on a significant guide, you're eligible for the prizes.
-
-h3. How is the process?
-
-* The preferred way to contribute is to commit to docrails directly.
-* A new guide is only edited by its author until finished though.
-* If you are writing a new guide freely commit to docrails partial work and ping lifo or fxn when done with a first draft.
-* Guides reviewers will then provide feedback, some of it possibly in form of direct commits to agilize the process.
-* Eventually the guide will be approved and added to the index.
-
-h3. Prizes
-
-For each completed guide, the lead contributor will receive all of the following prizes:
-
-* $200 from Caboose Rails Documentation Project.
-* 1 year of GitHub Micro account worth $84.
-* 1 year of RPM Basic (Production performance management) for up to 10 hosts worth 12 months x $40 per host x 10 hosts = $4800. And also, savings of $45 per host per month over list price to upgrade to advanced product.
-
-h3. Rules
-
-* Guides are licensed under a Creative Commons Attribution-Share Alike 3.0 License.
-* If you're not sure whether a guide is actively being worked on, stop by IRC and ask.
-* If the same guide writer wants to write multiple guides, that's ideally the situation we'd love to be in! However, that guide writer will only receive the cash prize for all the subsequent guides (and not the GitHub or RPM prizes).
-* Our review team will have the final say on whether the guide is complete and of good enough quality.
-
-All authors should read and follow the "Rails Guides Conventions":ruby_on_rails_guides_guidelines.html and the "Rails API Documentation Conventions":api_documentation_guidelines.html.
-
-h3. Translations
-
-The translation effort for the Rails Guides is just getting underway. We know about projects to translate the Guides into Spanish, Portuguese, Polish, and French. For more details or to get involved see the "Translating Rails Guides":https://wiki.github.com/lifo/docrails/translating-rails-guides page.
-
-h3. Mailing List
-
-"Ruby on Rails: Documentation":http://groups.google.com/group/rubyonrails-docs is the mailing list for all the guides/documentation related discussions.
-
-h3. Contact
-
-* IRC : #docrails channel in irc.freenode.net
-* Twitter: "@docrails":http://twitter.com/docrails, "@lifo":http://twitter.com/lifo, "@fxn":http://twitter.com/fxn
-* Email : pratiknaik aT gmail, fxn aT hashref dot com
--
cgit v1.2.3
From 7d235b972b29659d94e2b290be6e0ad3bc6a2668 Mon Sep 17 00:00:00 2001
From: dharmatech
Date: Mon, 12 Sep 2011 15:55:01 -0500
Subject: getting_started.textile: Fix typo and split up a sentence in section
"Building a Multi-Model Form"
---
railties/guides/source/getting_started.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 37aabcda83..b8dd4be73b 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1719,8 +1719,8 @@ This example shows another option of the render helper, being able to pass in
local variables, in this case, we want the local variable +form+ in the partial
to refer to the +post_form+ object.
-We also add a @post.tags.build at the top of this form, this is to make
-sure there is a new tag ready to have it's name filled in by the user. If you do
+We also add a @post.tags.build at the top of this form. This is to make
+sure there is a new tag ready to have its name filled in by the user. If you do
not build the new tag, then the form will not appear as there is no new Tag
object ready to create.
--
cgit v1.2.3
From 317ad8cb62d10f77cf0692f0a123b4a3358629a5 Mon Sep 17 00:00:00 2001
From: Mike Gunderloy
Date: Tue, 13 Sep 2011 06:47:13 -0500
Subject: Fix typo
---
railties/guides/source/rails_on_rack.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index 818df0ffaf..735438b155 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -216,7 +216,7 @@ config.middleware.clear
# config.ru
-use MyOwnStackFromStratch
+use MyOwnStackFromScratch
run ActionController::Dispatcher.new
--
cgit v1.2.3
From 7b22b0193002de14a4915f064acb4a7715c24059 Mon Sep 17 00:00:00 2001
From: 45north
Date: Tue, 13 Sep 2011 15:25:46 +0300
Subject: Fixed markup error.
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 9cc4dd5f04..8aabc3ae91 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -454,7 +454,7 @@ app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
TOPLEVEL_BINDING, config
-The initialize method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
+The +initialize+ method will take the block here and execute it within an instance of +Rack::Builder+. This is where the majority of the initialization process of Rails happens. The chain of events that this simple line sets off will be the focus of a large majority of this guide. The +require+ line for +config/environment.rb+ in +config.ru+ is the first to run:
require ::File.expand_path('../config/environment', __FILE__)
--
cgit v1.2.3
From d3baa928312a13ddd550a527caa554a49267ce88 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 13 Sep 2011 18:46:34 +0530
Subject: delete stray backup files from guides sample app
---
.../getting_started/app/views/home/index.html.erb~ | 2 -
.../guides/code/getting_started/config/routes.rb~ | 60 ----------------------
2 files changed, 62 deletions(-)
delete mode 100644 railties/guides/code/getting_started/app/views/home/index.html.erb~
delete mode 100644 railties/guides/code/getting_started/config/routes.rb~
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/app/views/home/index.html.erb~ b/railties/guides/code/getting_started/app/views/home/index.html.erb~
deleted file mode 100644
index 2085730c72..0000000000
--- a/railties/guides/code/getting_started/app/views/home/index.html.erb~
+++ /dev/null
@@ -1,2 +0,0 @@
-
Home#index
-
Find me in app/views/home/index.html.erb
diff --git a/railties/guides/code/getting_started/config/routes.rb~ b/railties/guides/code/getting_started/config/routes.rb~
deleted file mode 100644
index 3d9628b55e..0000000000
--- a/railties/guides/code/getting_started/config/routes.rb~
+++ /dev/null
@@ -1,60 +0,0 @@
-Blog::Application.routes.draw do
- get "home/index"
-
- # The priority is based upon order of creation:
- # first created -> highest priority.
-
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => 'welcome#index'
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
-end
--
cgit v1.2.3
From bde113a82e792ef3480d686a1e66fea56c76c46d Mon Sep 17 00:00:00 2001
From: Jaime Iniesta
Date: Wed, 14 Sep 2011 00:09:59 +0200
Subject: Fix typos and broken link on asset pipeline guide
---
railties/guides/source/asset_pipeline.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 211b02b94b..31a1aeee15 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -63,7 +63,7 @@ This has several disadvantages:
Not all caches will cache content with a query string
- "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached.
+ "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in this case 5-20% of requests will not be cached.
The file name can change between nodes in multi-server environments.
@@ -132,7 +132,7 @@ In regular views you can access images in the +assets/images+ directory like thi
Provided that the pipeline is enabled within your application (and not disabled in the current environment context), this file is served by Sprockets. If a file exists at +public/assets/rails.png+ it is served by the webserver.
-Alternatively, a request for a file with an MD5 hash such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is treated the same way. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide.
+Alternatively, a request for a file with an MD5 hash such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ is treated the same way. How these hashes are generated is covered in the "In Production":#in-production section later on in this guide.
Sprockets will also look through the paths specified in +config.assets.paths+ which includes the standard application paths and any path added by Rails engines.
@@ -537,7 +537,7 @@ WARNING: If you are upgrading an existing application and intend to use this opt
h3. How Caching Works
-Sprockets uses the default rails cache store to cache assets in development and production.
+Sprockets uses the default Rails cache store to cache assets in development and production.
TODO: Add more about changing the default store.
--
cgit v1.2.3
From b3ff720567b41ca5db9e6956c37cc0792b7a3f4e Mon Sep 17 00:00:00 2001
From: Ben Walding
Date: Wed, 14 Sep 2011 15:27:38 +1000
Subject: Add equivalent nginx configuration
---
railties/guides/source/asset_pipeline.textile | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 31a1aeee15..ce4eafb97c 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -403,7 +403,21 @@ For Apache:
-TODO: nginx instructions
+For nginx:
+
+
+location ~ ^/assets/ {
+ expires 1y;
+ add_header Cache-Control public;
+
+ # Some browsers still send conditional-GET requests if there's a
+ # Last-Modified header or an ETag header even if they haven't
+ # reached the expiry date sent in the Expires header.
+ add_header Last-Modified "";
+ add_header ETag "";
+ break;
+}
+
When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disk. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used:
--
cgit v1.2.3
From 7302e1cdf22951db1a4cbad45bf116db1be0eebb Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 14 Sep 2011 19:02:08 +0530
Subject: remove info about guides hackfest
---
railties/guides/source/index.html.erb | 1 -
1 file changed, 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index 214155c088..c9a8c4fa5c 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -30,7 +30,6 @@ Ruby on Rails Guides
<% content_for :index_section do %>
-
Rails Guides are a result of the ongoing Guides hackfest, and a work in progress.
Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections to the author.
--
cgit v1.2.3
From c7835c51618a6a46d1b5ec63dfaf2d99e157da42 Mon Sep 17 00:00:00 2001
From: Dallas Reedy
Date: Tue, 13 Sep 2011 16:32:43 -0700
Subject: Removed mention of deprecated proxy methods in favor of using
proxy_association.
---
railties/guides/source/association_basics.textile | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index ce4ff0389d..0439b6ac4d 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -1855,14 +1855,15 @@ class Customer < ActiveRecord::Base
end
+
+
+!images/i18n/demo_html_safe.png(i18n demo html safe)!
+
h3. How to Store your Custom Translations
The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and YAML format. [2]
--
cgit v1.2.3
From 28677014a4f8121272a17870246507e86e46837c Mon Sep 17 00:00:00 2001
From: Guillermo Iguaran
Date: Thu, 15 Sep 2011 20:07:01 -0500
Subject: Add reference about --skip-sprockets to Asset Pipeline Guide
---
railties/guides/source/asset_pipeline.textile | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index ce4eafb97c..74dfdfb540 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -25,6 +25,12 @@ In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +a
config.assets.enabled = false
+You can also disable it when you are creating a new application passing the --skip-sprockets parameter:
+
+
+rails new appname --skip-sprockets
+
+
It is recommended that you use the defaults for all new apps.
--
cgit v1.2.3
From 302e570777b1ca8f537c96628334dcbe8a94d83f Mon Sep 17 00:00:00 2001
From: Kir Shatrov
Date: Fri, 16 Sep 2011 17:43:05 +0400
Subject: "Passing variables into the translation" section added
---
railties/guides/source/i18n.textile | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 76cd14d479..a35cd6c506 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -365,6 +365,20 @@ NOTE: You need to restart the server when you add new locale files.
You may use YAML (+.yml+) or plain Ruby (+.rb+) files for storing your translations in SimpleStore. YAML is the preferred option among Rails developers. However, it has one big disadvantage. YAML is very sensitive to whitespace and special characters, so the application may not load your dictionary properly. Ruby files will crash your application on first request, so you may easily find what's wrong. (If you encounter any "weird issues" with YAML dictionaries, try putting the relevant portion of your dictionary into a Ruby file.)
+h4. Passing variables into the translation
+
+You may use translation with parameters, if you want.
+
+
+# app/views/home/index.html.erb
+
+
+# config/locales/en.yml
+en:
+ greet_username: "%{message}, %{user}!"
+
+
h4. Adding Date/Time Formats
OK! Now let's add a timestamp to the view, so we can demo the *date/time localization* feature as well. To localize the time format you pass the Time object to +I18n.l+ or (preferably) use Rails' +#l+ helper. You can pick a format by passing the +:format+ option -- by default the +:default+ format is used.
--
cgit v1.2.3
From 8411f631c42de7d6f51d10d997b037b9eff0d1f1 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 16 Sep 2011 23:22:03 +0530
Subject: minor edit
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 74dfdfb540..bea5e494d5 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -25,7 +25,7 @@ In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +a
config.assets.enabled = false
-You can also disable it when you are creating a new application passing the --skip-sprockets parameter:
+You can also disable it while creating a new application by passing the --skip-sprockets option.
rails new appname --skip-sprockets
--
cgit v1.2.3
From 27f1320fde03279c575693f504897f1a6171bc59 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 16 Sep 2011 22:12:41 +0530
Subject: Fixing incorrect notextile tags
---
.../guides/source/action_view_overview.textile | 2 +-
.../active_record_validations_callbacks.textile | 4 ++--
.../source/active_support_core_extensions.textile | 26 +++++++++++-----------
railties/guides/source/ajax_on_rails.textile | 4 +++-
.../source/api_documentation_guidelines.textile | 2 +-
railties/guides/source/asset_pipeline.textile | 2 +-
railties/guides/source/initialization.textile | 2 +-
.../source/ruby_on_rails_guides_guidelines.textile | 2 +-
railties/guides/source/security.textile | 6 ++---
9 files changed, 26 insertions(+), 24 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index 87250c684b..40cde6ad84 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -898,7 +898,7 @@ h5. select_year
Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius can be changed using the +:start_year+ and +:end_year+ keys in the +options+.
-# Generates a select field for five years on either side of +Date.today+ that defaults to the current year
+# Generates a select field for five years on either side of Date.today that defaults to the current year
select_year(Date.today)
# Generates a select field from 1900 to 2009 that defaults to the current year
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 20f5e52891..5c3aae2955 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -328,7 +328,7 @@ This helper validates that your attributes have only numeric values. By default,
If you set +:only_integer+ to +true+, then it will use the
-/\A[+-]?\d+\Z/
+/\A[-]?\d\Z/
regular expression to validate the attribute's value. Otherwise, it will try to convert the value to a number using +Float+.
@@ -597,7 +597,7 @@ The easiest way to add custom validators for validating individual attributes is
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ unless value =~ /\A([^@\s])@((?:[-a-z0-9]\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || "is not an email")
end
end
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index d006cc9214..b3d8760a73 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -296,7 +296,7 @@ This method escapes whatever is needed, both for the key and the value:
account.to_query('company[name]')
-# => "company%5Bname%5D=Johnson+%26+Johnson"
+# => "company%5Bname%5D=Johnson%26Johnson"
so its output is ready to be used in a query string.
@@ -3385,11 +3385,11 @@ They are analogous. Please refer to their documentation above and take into acco
Time.zone_default
# => #
-# In Barcelona, 2010/03/28 02:00 +0100 becomes 2010/03/28 03:00 +0200 due to DST.
+# In Barcelona, 2010/03/28 02:00 0100 becomes 2010/03/28 03:00 0200 due to DST.
t = Time.local_time(2010, 3, 28, 1, 59, 59)
-# => Sun Mar 28 01:59:59 +0100 2010
+# => Sun Mar 28 01:59:59 0100 2010
t.advance(:seconds => 1)
-# => Sun Mar 28 03:00:00 +0200 2010
+# => Sun Mar 28 03:00:00 0200 2010
* If +since+ or +ago+ jump to a time that can't be expressed with +Time+ a +DateTime+ object is returned instead.
@@ -3406,24 +3406,24 @@ The method +all_day+ returns a range representing the whole day of the current t
now = Time.current
-# => Mon, 09 Aug 2010 23:20:05 UTC +00:00
+# => Mon, 09 Aug 2010 23:20:05 UTC 00:00
now.all_day
-# => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Mon, 09 Aug 2010 23:59:59 UTC +00:00
+# => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Mon, 09 Aug 2010 23:59:59 UTC 00:00
Analogously, +all_week+, +all_month+, +all_quarter+ and +all_year+ all serve the purpose of generating time ranges.
now = Time.current
-# => Mon, 09 Aug 2010 23:20:05 UTC +00:00
+# => Mon, 09 Aug 2010 23:20:05 UTC 00:00
now.all_week
-# => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Sun, 15 Aug 2010 23:59:59 UTC +00:00
+# => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Sun, 15 Aug 2010 23:59:59 UTC 00:00
now.all_month
-# => Sat, 01 Aug 2010 00:00:00 UTC +00:00..Tue, 31 Aug 2010 23:59:59 UTC +00:00
+# => Sat, 01 Aug 2010 00:00:00 UTC 00:00..Tue, 31 Aug 2010 23:59:59 UTC 00:00
now.all_quarter
-# => Thu, 01 Jul 2010 00:00:00 UTC +00:00..Thu, 30 Sep 2010 23:59:59 UTC +00:00
+# => Thu, 01 Jul 2010 00:00:00 UTC 00:00..Thu, 30 Sep 2010 23:59:59 UTC 00:00
now.all_year
-# => Fri, 01 Jan 2010 00:00:00 UTC +00:00..Fri, 31 Dec 2010 23:59:59 UTC +00:00
+# => Fri, 01 Jan 2010 00:00:00 UTC 00:00..Fri, 31 Dec 2010 23:59:59 UTC 00:00
h4. Time Constructors
@@ -3434,7 +3434,7 @@ Active Support defines +Time.current+ to be +Time.zone.now+ if there's a user ti
Time.zone_default
# => #
Time.current
-# => Fri, 06 Aug 2010 17:11:58 CEST +02:00
+# => Fri, 06 Aug 2010 17:11:58 CEST 02:00
Analogously to +DateTime+, the predicates +past?+, and +future?+ are relative to +Time.current+.
@@ -3445,7 +3445,7 @@ Use the +local_time+ class method to create time objects honoring the user time
Time.zone_default
# => #
Time.local_time(2010, 8, 15)
-# => Sun Aug 15 00:00:00 +0200 2010
+# => Sun Aug 15 00:00:00 0200 2010
The +utc_time+ class method returns a time in UTC:
diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile
index 77f7661deb..29d4fae888 100644
--- a/railties/guides/source/ajax_on_rails.textile
+++ b/railties/guides/source/ajax_on_rails.textile
@@ -104,7 +104,7 @@ Note that if we wouldn't override the default behavior (POST), the above snippet
link_to_remote "Update record",
:url => record_url(record),
:method => :put,
- :with => "'status=' + 'encodeURIComponent($('status').value) + '&completed=' + $('completed')"
+ :with => "'status=' 'encodeURIComponent($('status').value) '&completed=' $('completed')"
This generates a remote link which adds 2 parameters to the standard URL generated by Rails, taken from the page (contained in the elements matched by the 'status' and 'completed' DOM id).
@@ -124,6 +124,7 @@ link_to_remote "Add new item",
404 => "alert('Item not found!')"
Let's see a typical example for the most frequent callbacks, +:success+, +:failure+ and +:complete+ in action:
+
link_to_remote "Add new item",
:url => items_url,
@@ -133,6 +134,7 @@ link_to_remote "Add new item",
:success => "display_item_added(request)",
:failure => "display_error(request)"
+
** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+.
* Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though:
** If you specify the +href+ parameter, the AJAX link will degrade gracefully, i.e. the link will point to the URL even if JavaScript is disabled in the client browser
diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile
index c0f709eda8..99eb668513 100644
--- a/railties/guides/source/api_documentation_guidelines.textile
+++ b/railties/guides/source/api_documentation_guidelines.textile
@@ -146,7 +146,7 @@ h3. Description Lists
In lists of options, parameters, etc. use a hyphen between the item and its description (reads better than a colon because normally options are symbols):
-# * :allow_nil - Skip validation if attribute is +nil+.
+# * :allow_nil - Skip validation if attribute is nil.
The description starts in upper case and ends with a full stop—it's standard English.
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index bea5e494d5..e03ae736a8 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -359,7 +359,7 @@ NOTE. If you are precompiling your assets locally, you can use +bundle install -
The default matcher for compiling files includes +application.js+, +application.css+ and all files that do not end in +js+ or +css+:
-[ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
+[ /\w\.(?!js|css)./, /application.(css|js)$/ ]
If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the +precompile+ array:
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 8aabc3ae91..32b41fdd2c 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -450,7 +450,7 @@ run YourApp::Application
The +Rack::Builder.parse_file+ method here takes the content from this +config.ru+ file and parses it using this code:
-app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
+app = eval "Rack::Builder.new {( " cfgfile "\n )}.to_app",
TOPLEVEL_BINDING, config
diff --git a/railties/guides/source/ruby_on_rails_guides_guidelines.textile b/railties/guides/source/ruby_on_rails_guides_guidelines.textile
index e63f564c83..29aefd25f8 100644
--- a/railties/guides/source/ruby_on_rails_guides_guidelines.textile
+++ b/railties/guides/source/ruby_on_rails_guides_guidelines.textile
@@ -26,7 +26,7 @@ h5. When are Objects Saved?
Use the same typography as in regular text:
-h6. The +:content_type+ Option
+h6. The :content_type Option
h3. API Documentation Guidelines
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index 4cf9e2a7f3..73c7a80ff6 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -582,7 +582,7 @@ Ruby uses a slightly different approach than many other languages to match the e
class File < ActiveRecord::Base
- validates :name, :format => /^[\w\.\-\+]+$/
+ validates :name, :format => /^[\w\.\-\]$/
end
@@ -595,7 +595,7 @@ file.txt%0A
Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n<script>alert('hello')</script>". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read:
-/\A[\w\.\-\+]+\z/
+/\A[\w\.\-\]\z/
h4. Privilege Escalation
@@ -762,7 +762,7 @@ These examples don't do any harm so far, so let's see how an attacker can steal
For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server's access log files to see the victim's cookie.
-
+
The log files on www.attacker.com will read like this:
--
cgit v1.2.3
From 663031801cac577a88931cdfe6f062555112f370 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?U=C4=A3is=20Ozols?=
Date: Sat, 17 Sep 2011 10:00:53 +0300
Subject: sass-rails helpers - hyphenated in Sass, underscored in Ruby.
---
railties/guides/source/asset_pipeline.textile | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index e03ae736a8..586a9f46eb 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -170,15 +170,15 @@ Note that the closing tag cannot be of the style +-%>+.
h5. CSS and Sass
-When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, JavaScript and stylesheet.
+When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +-url+ and +-path+ helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.
-* +image_url("rails.png")+ becomes +url(/assets/rails.png)+.
-* +image_path("rails.png")+ becomes +"/assets/rails.png"+.
+* +image-url("rails.png")+ becomes +url(/assets/rails.png)+
+* +image-path("rails.png")+ becomes +"/assets/rails.png"+.
The more generic form can also be used but the asset path and class must both be specified:
-* +asset_url("rails.png", image)+ becomes +url(/assets/rails.png)+.
-* +asset_path("rails.png", image)+ becomes +"/assets/rails.png"+.
+* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+
+* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+
h5. JavaScript/CoffeeScript and ERB
--
cgit v1.2.3
From ea29968bcfa455d9bef8c41436b6bea669dfc06d Mon Sep 17 00:00:00 2001
From: Jan Vlnas
Date: Sun, 18 Sep 2011 16:41:21 +0300
Subject: Locale code for Czech is ":cs"
---
railties/guides/source/i18n.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index a35cd6c506..14ce6a19d5 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -91,7 +91,7 @@ This means, that in the +:en+ locale, the key _hello_ will map to the _Hello wor
The I18n library will use *English* as a *default locale*, i.e. if you don't set a different locale, +:en+ will be used for looking up translations.
-NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cz+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-UK+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it.
+NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-UK+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it.
The *translations load path* (+I18n.load_path+) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you.
--
cgit v1.2.3
From 7ed97bc8149f745317a897304c8c86f0e3bba4d2 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 20 Sep 2011 19:33:01 +0530
Subject: remove unnecessary markup
---
.../guides/source/active_support_core_extensions.textile | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index b3d8760a73..e81fe13010 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3387,9 +3387,9 @@ Time.zone_default
# In Barcelona, 2010/03/28 02:00 0100 becomes 2010/03/28 03:00 0200 due to DST.
t = Time.local_time(2010, 3, 28, 1, 59, 59)
-# => Sun Mar 28 01:59:59 0100 2010
+# => Sun Mar 28 01:59:59 +0100 2010
t.advance(:seconds => 1)
-# => Sun Mar 28 03:00:00 0200 2010
+# => Sun Mar 28 03:00:00 +0200 2010
* If +since+ or +ago+ jump to a time that can't be expressed with +Time+ a +DateTime+ object is returned instead.
@@ -3406,7 +3406,7 @@ The method +all_day+ returns a range representing the whole day of the current t
now = Time.current
-# => Mon, 09 Aug 2010 23:20:05 UTC 00:00
+# => Mon, 09 Aug 2010 23:20:05 UTC +00:00
now.all_day
# => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Mon, 09 Aug 2010 23:59:59 UTC 00:00
@@ -3415,7 +3415,7 @@ Analogously, +all_week+, +all_month+, +all_quarter+ and +all_year+ all serve the
now = Time.current
-# => Mon, 09 Aug 2010 23:20:05 UTC 00:00
+# => Mon, 09 Aug 2010 23:20:05 UTC +00:00
now.all_week
# => Mon, 09 Aug 2010 00:00:00 UTC 00:00..Sun, 15 Aug 2010 23:59:59 UTC 00:00
now.all_month
@@ -3434,7 +3434,7 @@ Active Support defines +Time.current+ to be +Time.zone.now+ if there's a user ti
Time.zone_default
# => #
Time.current
-# => Fri, 06 Aug 2010 17:11:58 CEST 02:00
+# => Fri, 06 Aug 2010 17:11:58 CEST +02:00
Analogously to +DateTime+, the predicates +past?+, and +future?+ are relative to +Time.current+.
@@ -3445,7 +3445,7 @@ Use the +local_time+ class method to create time objects honoring the user time
Time.zone_default
# => #
Time.local_time(2010, 8, 15)
-# => Sun Aug 15 00:00:00 0200 2010
+# => Sun Aug 15 00:00:00 +0200 2010
The +utc_time+ class method returns a time in UTC:
--
cgit v1.2.3
From 5684ecf74966d81e6fa7193689881b5243cbbc39 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 20 Sep 2011 19:47:33 +0530
Subject: copy edits 302e5707
---
railties/guides/source/i18n.textile | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 14ce6a19d5..11e1473ba2 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -365,14 +365,13 @@ NOTE: You need to restart the server when you add new locale files.
You may use YAML (+.yml+) or plain Ruby (+.rb+) files for storing your translations in SimpleStore. YAML is the preferred option among Rails developers. However, it has one big disadvantage. YAML is very sensitive to whitespace and special characters, so the application may not load your dictionary properly. Ruby files will crash your application on first request, so you may easily find what's wrong. (If you encounter any "weird issues" with YAML dictionaries, try putting the relevant portion of your dictionary into a Ruby file.)
-h4. Passing variables into the translation
+h4. Passing variables to translations
-You may use translation with parameters, if you want.
+You can use variables in the translation messages and pass their values from the view.
# app/views/home/index.html.erb
-
+<%=t 'greet_username', :user => "Bill", :message => "Goodbye" %>
# config/locales/en.yml
en:
--
cgit v1.2.3
From 564d7edf690ab60e439df7d7dfebc5144d8d1867 Mon Sep 17 00:00:00 2001
From: Waynn Lue
Date: Wed, 21 Sep 2011 01:28:59 -0700
Subject: add a '.' to etc
---
railties/guides/source/i18n.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 11e1473ba2..81d2ba9a56 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -12,7 +12,7 @@ So, in the process of _internationalizing_ your Rails application you have to:
In the process of _localizing_ your application you'll probably want to do the following three things:
-* Replace or supplement Rails' default locale -- e.g. date and time formats, month names, Active Record model names, etc
+* Replace or supplement Rails' default locale -- e.g. date and time formats, month names, Active Record model names, etc.
* Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc.
* Store the resulting dictionaries somewhere
--
cgit v1.2.3
From 3c5340ec9cbf12d19e734289ba748186af492d60 Mon Sep 17 00:00:00 2001
From: Waynn Lue
Date: Wed, 21 Sep 2011 02:10:07 -0700
Subject: add a missing "on" and remove the "endprologue" text
---
railties/guides/source/i18n.textile | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 81d2ba9a56..46f6942d02 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -16,9 +16,7 @@ In the process of _localizing_ your application you'll probably want to do the f
* Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc.
* Store the resulting dictionaries somewhere
-This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start.
-
-endprologue.
+This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start.
NOTE: The Ruby I18n framework provides you with all necessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See the Rails "I18n Wiki":http://rails-i18n.org/wiki for more information.
--
cgit v1.2.3
From 8d7aee71738fbf1ff090ff44a09624e592b94b04 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 21 Sep 2011 02:19:44 +0530
Subject: indentation fixes
---
railties/guides/source/active_support_core_extensions.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index e81fe13010..5aee001545 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3518,8 +3518,8 @@ h4. +around_[level]+
Takes two arguments, a +before_message+ and +after_message+ and calls the current level method on the +Logger+ instance, passing in the +before_message+, then the specified message, then the +after_message+:
- logger = Logger.new("log/development.log")
- logger.around_info("before", "after") { |logger| logger.info("during") }
+logger = Logger.new("log/development.log")
+logger.around_info("before", "after") { |logger| logger.info("during") }
h4. +silence+
--
cgit v1.2.3
From 3e80462b95808457eb1584195909e26887a1a40d Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 21 Sep 2011 19:28:36 +0530
Subject: Revert "add a missing "on" and remove the "endprologue" text"
This reverts commit 3c5340ec9cbf12d19e734289ba748186af492d60.
Reason: endprologue should not have been removed.
---
railties/guides/source/i18n.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 46f6942d02..81d2ba9a56 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -16,7 +16,9 @@ In the process of _localizing_ your application you'll probably want to do the f
* Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc.
* Store the resulting dictionaries somewhere
-This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start.
+This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start.
+
+endprologue.
NOTE: The Ruby I18n framework provides you with all necessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See the Rails "I18n Wiki":http://rails-i18n.org/wiki for more information.
--
cgit v1.2.3
From efb8a7a7b928c8075a20ea46d9ac657ef56a7faa Mon Sep 17 00:00:00 2001
From: Christopher Arrowsmith
Date: Thu, 22 Sep 2011 01:18:22 +0100
Subject: Changed "en-UK" to "en-GB"
Signed-off-by: Christopher Arrowsmith
---
railties/guides/source/i18n.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 81d2ba9a56..45a069b0a3 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -91,7 +91,7 @@ This means, that in the +:en+ locale, the key _hello_ will map to the _Hello wor
The I18n library will use *English* as a *default locale*, i.e. if you don't set a different locale, +:en+ will be used for looking up translations.
-NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-UK+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it.
+NOTE: The i18n library takes a *pragmatic approach* to locale keys (after "some discussion":http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-GB+, which are traditionally used for separating "languages" and "regional setting" or "dialects". Many international applications use only the "language" element of a locale such as +:cs+, +:th+ or +:es+ (for Czech, Thai and Spanish). However, there are also regional differences within different language groups that may be important. For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-GB+, you would have £. Nothing stops you from separating regional and other settings in this way: you just have to provide full "English - United Kingdom" locale in a +:en-GB+ dictionary. Various "Rails I18n plugins":http://rails-i18n.org/wiki such as "Globalize2":https://github.com/joshmh/globalize2/tree/master may help you implement it.
The *translations load path* (+I18n.load_path+) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you.
--
cgit v1.2.3
From 17ba60a724aad508327bf52212335420f4d81364 Mon Sep 17 00:00:00 2001
From: Waynn Lue
Date: Fri, 23 Sep 2011 00:25:37 -0700
Subject: pluralize "locales" since that's what's used in other parts of the
document, and add a missing "on"
---
railties/guides/source/i18n.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 45a069b0a3..2d4cc13571 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -8,7 +8,7 @@ So, in the process of _internationalizing_ your Rails application you have to:
* Ensure you have support for i18n
* Tell Rails where to find locale dictionaries
-* Tell Rails how to set, preserve and switch locale
+* Tell Rails how to set, preserve and switch locales
In the process of _localizing_ your application you'll probably want to do the following three things:
@@ -16,7 +16,7 @@ In the process of _localizing_ your application you'll probably want to do the f
* Abstract strings in your application into keyed dictionaries -- e.g. flash messages, static text in your views, etc.
* Store the resulting dictionaries somewhere
-This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start.
+This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start.
endprologue.
--
cgit v1.2.3
From 4b9b2f3d048906337d936ec6b85cd13a92b51448 Mon Sep 17 00:00:00 2001
From: Chris Kimpton
Date: Mon, 26 Sep 2011 08:06:41 +0200
Subject: add some notes on setup for Active Record tests
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 30714e7e18..20263b1b37 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -120,6 +120,12 @@ The test suite of Active Record attempts to run four times, once for SQLite3, on
WARNING: If you're working with Active Record code, you _must_ ensure that the tests pass for at least MySQL, PostgreSQL, and SQLite3. Subtle differences between the various adapters have been behind the rejection of many patches that looked OK when tested only against MySQL.
+h5. Set up Database Configuration
+
+The Acitve Record test suite requires a custom config file: +activerecord/test/config.yml+ . An example is provided: +activerecord/test/config.example.yml+ - copy this and amend as needed for your environment.
+
+The SQLite3 config should work "as is".
+
h5. SQLite3
The gem +sqlite3-ruby+ does not belong to the "db" group indeed, if you followed the instructions above you're ready. This is how you run the Active Record test suite only for SQLite3:
--
cgit v1.2.3
From d47c2c4620f0580390d2009dc8dedc07b9f4c3bd Mon Sep 17 00:00:00 2001
From: Chris Kimpton
Date: Mon, 26 Sep 2011 08:17:28 +0200
Subject: Clarify that the Active Record config should just work automatically
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 20263b1b37..678df55d51 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -122,7 +122,11 @@ WARNING: If you're working with Active Record code, you _must_ ensure that the t
h5. Set up Database Configuration
-The Acitve Record test suite requires a custom config file: +activerecord/test/config.yml+ . An example is provided: +activerecord/test/config.example.yml+ - copy this and amend as needed for your environment.
+The Acitve Record test suite requires a custom config file: +activerecord/test/config.yml+ .
+An example is provided: +activerecord/test/config.example.yml+ - copy this and amend as needed for your environment.
+
+The above should happen automatically - so this section may be removed when the underlying issue that causes the file to be
+missing/corrupt is resolved.
The SQLite3 config should work "as is".
--
cgit v1.2.3
From 51cc6e4f1cc17c461544a4b099deff5a579978c9 Mon Sep 17 00:00:00 2001
From: Chris Kimpton
Date: Mon, 26 Sep 2011 09:21:12 +0200
Subject: Fixed typo that I added - doh.
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 678df55d51..dafeb8d85e 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -122,7 +122,7 @@ WARNING: If you're working with Active Record code, you _must_ ensure that the t
h5. Set up Database Configuration
-The Acitve Record test suite requires a custom config file: +activerecord/test/config.yml+ .
+The Active Record test suite requires a custom config file: +activerecord/test/config.yml+ .
An example is provided: +activerecord/test/config.example.yml+ - copy this and amend as needed for your environment.
The above should happen automatically - so this section may be removed when the underlying issue that causes the file to be
--
cgit v1.2.3
From 94ed1e24956c5d6d3482517d10134938d37e837d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicol=C3=A1s=20Hock=20Isaza?=
Date: Mon, 26 Sep 2011 16:34:42 -0500
Subject: Alert about the new Bundler require for asset gems
If you are coming from a Rails 3.0 application, you won't have
the correct Bundler require statement.
This will cause the gems under the `assets` group not to be available
in the development and production environment.
I think this is related to the issue #39 in rails-sass
https://github.com/rails/sass-rails/issues/39
---
railties/guides/source/asset_pipeline.textile | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 586a9f46eb..3428c09bcd 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -247,9 +247,9 @@ h4. Preprocessing
The file extensions used on an asset determine what preprocessing is applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file are generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file.
When these files are requested, they are processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively.
-
Additional layers of pre-processing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ is first processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file -- +app/assets/javascripts/projects.js.coffee.erb+ is processed as ERB, CoffeeScript and served as JavaScript.
+
Keep in mind that the order of these pre-processors is important. For example, if you called your JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it is processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems.
h3. In Development
@@ -636,3 +636,22 @@ group :assets do
gem 'uglifier'
end
+
+If you use the +assets+ group with Bundler, please make sure that your +config/application.rb+ has the following Bundler require statement.
+
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require *Rails.groups(:assets => %w(development test))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+
+Instead of the old Rails 3.0 one
+
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
\ No newline at end of file
--
cgit v1.2.3
From 01e5e2faebb4a8082d38eb585762dc16ce3698f7 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Mon, 26 Sep 2011 18:18:52 -0700
Subject: partial pass over the asset pipeline guide
---
railties/guides/source/asset_pipeline.textile | 42 ++++++++++++++-------------
1 file changed, 22 insertions(+), 20 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 586a9f46eb..c0694dda4e 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -17,13 +17,13 @@ The asset pipeline provides a framework to concatenate and minify or compress Ja
Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through Action Pack which depends on the +sprockets+ gem, by default.
-By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf.
+By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "fast by default" strategy as outlined by DHH in his keynote at RailsConf 2011.
-In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition:
+In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by putting this line inside the application class definition:
-
+
config.assets.enabled = false
-
+
You can also disable it while creating a new application by passing the --skip-sprockets option.
@@ -36,7 +36,9 @@ It is recommended that you use the defaults for all new apps.
h4. Main Features
-The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page. While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ -- many people do not use it.
+The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page.
+
+While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ --, it has a series of limitations. For example, it cannot generate the caches in advance, and it is not able to transparently include assets provided by third-party libraries.
The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production, an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered.
@@ -46,14 +48,14 @@ The third feature is the ability to code these assets using another language, or
h4. What is Fingerprinting and Why Should I Care?
-Fingerprinting is a technique whereby the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file.
+Fingerprinting is a technique whereby the filenames of content that is static or infrequently updated are altered to be unique to the content contained in the file.
-When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cachebusting_.
+When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cache busting_.
-The most effective technique is to insert a hash of the content into the name, usually at the end. For example a CSS file +global.css+ is hashed and the filename is updated to incorporate the hash.
+The most effective technique is to insert a hash of the content into the name, usually at the end. For example a CSS file +global.css+ is hashed and the filename is updated to incorporate the digest, for example becoming:
-global.css => global-908e25f4bf641868d8683022a5b62f54.css
+global-908e25f4bf641868d8683022a5b62f54.css
This is the strategy adopted by the Rails asset pipeline.
@@ -68,8 +70,8 @@ This has several disadvantages:
- Not all caches will cache content with a query string
- "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in this case 5-20% of requests will not be cached.
+ Not all caches will cache content with a query string.
+ "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in this case 5-20% of requests will not be cached. Query strings in particular do not work at all with some CDNs for cache invalidation.
The file name can change between nodes in multi-server environments.
@@ -77,9 +79,9 @@ This has several disadvantages:
-The other problem is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed.
+The other problem is that when static assets are deployed with each new release of code, the mtime of _all_ these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed.
-Fingerprinting avoids all these problems by ensuring filenames are consistent based on their content.
+Fingerprinting fixes these problems by avoiding query strings, and by ensuring filenames are consistent based on their content.
Fingerprinting is enabled by default for production and disabled for all the others environments. You can enable or disable it in your configuration through the +config.assets.digest+ option.
@@ -95,7 +97,7 @@ In previous versions of Rails, all assets were located in subdirectories of +pub
This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served.
-In production, the default is to precompile these files to +public/assets+ so that they can be more efficiently delivered by the webserver.
+In production, the default is to precompile these files to +public/assets+ so that they can be more efficiently delivered by the web server.
When a scaffold or controller is generated for the application, Rails also generates a JavaScript file (or CoffeeScript file if the +coffee-rails+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS file if +sass-rails+ is in the +Gemfile+) for that controller.
@@ -115,11 +117,11 @@ Assets can be placed inside an application in one of three locations: +app/asset
All subdirectories that exist within these three locations are added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths are traversed to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served.
-You can add additional (fully qualified) paths to the pipeline in +application.rb+. For example:
+You can add additional (fully qualified) paths to the pipeline in +config/application.rb+. For example:
-
-config.assets.paths << File.join(Rails.root, 'app', 'assets', 'flash')
-
+
+config.assets.paths << "#{Rails.root}/app/assets/flash"
+
h4. Coding Links to Assets
@@ -150,10 +152,10 @@ Images can also be organized into subdirectories if required, and they can be ac
h5. CSS and ERB
-If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then you can use the +asset_path+ helper in your CSS rules:
+If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then helpers like +image_path+ are available in your CSS rules:
-.class { background-image: url(<%= asset_path 'image.png' %>) }
+.class { background-image: url(<%= image_path 'image.png' %>) }
This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced.
--
cgit v1.2.3
From cb5c39f8a0af78e933d1fe0456c112db1e97813f Mon Sep 17 00:00:00 2001
From: Justin Leitgeb
Date: Mon, 26 Sep 2011 22:22:52 -0400
Subject: Make the Rack::SSL middleware configurable
---
railties/guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index cad2d03c23..41b53440f7 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -179,7 +179,7 @@ h4. Configuring Middleware
Every Rails application comes with a standard set of middleware which it uses in this order in the development environment:
-* +Rack::SSL+ Will force every request to be under HTTPS protocol. Will be available if +config.force_ssl+ is set to +true+.
+* +Rack::SSL+ Will force every request to be under HTTPS protocol. Will be available if +config.force_ssl+ is set to +true+. Options passed to this can be configured by using +config.ssl_options+.
* +ActionDispatch::Static+ is used to serve static assets. Disabled if +config.serve_static_assets+ is +true+.
* +Rack::Lock+ Will wrap the app in mutex so it can only be called by a single thread at a time. Only enabled if +config.action_controller.allow_concurrency+ is set to +false+, which it is by default.
* +ActiveSupport::Cache::Strategy::LocalCache+ Serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
--
cgit v1.2.3
From a775853d6aabaadcd343b2f61bcbc7c7e2c59363 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 28 Sep 2011 00:00:50 +0530
Subject: copy edit d47c2c4
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index dafeb8d85e..5848172510 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -122,13 +122,7 @@ WARNING: If you're working with Active Record code, you _must_ ensure that the t
h5. Set up Database Configuration
-The Active Record test suite requires a custom config file: +activerecord/test/config.yml+ .
-An example is provided: +activerecord/test/config.example.yml+ - copy this and amend as needed for your environment.
-
-The above should happen automatically - so this section may be removed when the underlying issue that causes the file to be
-missing/corrupt is resolved.
-
-The SQLite3 config should work "as is".
+The Active Record test suite requires a custom config file: +activerecord/test/config.yml+. An example is provided in +activerecord/test/config.example.yml+ which can be copied and used as needed for your environment.
h5. SQLite3
--
cgit v1.2.3
From c612183ad19f2c11eb58e4393a759a1016ce4c05 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Tue, 27 Sep 2011 13:50:49 -0700
Subject: partial pass over the asset pipeline
---
railties/guides/source/asset_pipeline.textile | 31 +++++++++++++++------------
1 file changed, 17 insertions(+), 14 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index b343e8d01d..c5bbe3226a 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -152,15 +152,15 @@ Images can also be organized into subdirectories if required, and they can be ac
h5. CSS and ERB
-If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then helpers like +image_path+ are available in your CSS rules:
+If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then helpers like +asset_path+ are available in your CSS rules:
-.class { background-image: url(<%= image_path 'image.png' %>) }
+.class { background-image: url(<%= asset_path 'image.png' %>) }
This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced.
-If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper.
+If you want to use a "data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper.
#logo { background: url(<%= asset_data_uri 'logo.png' %>) }
@@ -186,27 +186,28 @@ h5. JavaScript/CoffeeScript and ERB
If you add an +erb+ extension to a JavaScript asset, making it something such as +application.js.erb+, then you can use the +asset_path+ helper in your JavaScript code:
-
+
$('#logo').attr({
src: "<%= asset_path('logo.png') %>"
});
-
+
This writes the path to the particular asset being referenced.
-Similarly, you can use the +asset_path+ helper in CoffeeScript files with +erb+ extension (eg. application.js.coffee.erb):
+Similarly, you can use the +asset_path+ helper in CoffeeScript files with +erb+ extension (eg. +application.js.coffee.erb+):
-$('#logo').attr src: "<% asset_path('logo.png') %>"
+$('#logo').attr src: "<%= asset_path('logo.png') %>"
h4. Manifest Files and Directives
-Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make.
+Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is true). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make.
For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines:
+// ...
//= require jquery
//= require jquery_ujs
//= require_tree .
@@ -214,9 +215,11 @@ For example, in the default Rails application there's a +app/assets/javascripts/
In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets the files that you wish to require. Here, you are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. You need not supply the extensions explicitly. Sprockets assumes you are requiring a +.js+ file when done from within a +.js+ file.
-NOTE. In Rails 3.1, the +jquery.js+ and +jquery_ujs.js+ files are located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem.
+NOTE. In Rails 3.1 the +jquery-rails+ gem provides the +jquery.js+ and +jquery_ujs.js+ files via the asset pipeline. You won't see them in the application tree.
+
+The +require_tree+ directive tells Sprockets to recursively include _all_ JavaScript files in this directory into the output. Only a path relative to the manifest file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting).
-The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting).
+Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output.
There's also a default +app/assets/stylesheets/application.css+ file which contains these lines:
@@ -233,7 +236,7 @@ In this example +require_self+ is used. This puts the CSS contained within the f
You can have as many manifest files as you need. For example the +admin.css+ and +admin.js+ manifest could contain the JS and CSS files that are used for the admin section of an application.
-For some assets (like CSS) the compiled order is important. You can specify individual files and they are compiled in the order specified:
+The same remarks about ordering made above apply. In particular, you can specify individual files and they are compiled in the order specified:
/* ...
@@ -246,13 +249,13 @@ For some assets (like CSS) the compiled order is important. You can specify indi
h4. Preprocessing
-The file extensions used on an asset determine what preprocessing is applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file are generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file.
+The file extensions used on an asset determine what preprocessing is applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file are generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and an +app/assets/stylesheets/projects.css.scss+ file.
When these files are requested, they are processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively.
-Additional layers of pre-processing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ is first processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file -- +app/assets/javascripts/projects.js.coffee.erb+ is processed as ERB, CoffeeScript and served as JavaScript.
+Additional layers of preprocessing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ is first processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file -- +app/assets/javascripts/projects.js.coffee.erb+ is processed as ERB, CoffeeScript, and served as JavaScript.
-Keep in mind that the order of these pre-processors is important. For example, if you called your JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it is processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems.
+Keep in mind that the order of these preprocessors is important. For example, if you called your JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it would be processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems.
h3. In Development
--
cgit v1.2.3
From 41c8277a9b04dda40972bbafa2dbfc00c5c238fb Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Tue, 27 Sep 2011 13:55:41 -0700
Subject: the infamous detail only spotted in GitHub diffs no matter how
careful you were before pushing
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index c5bbe3226a..8a15618eb2 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -219,7 +219,7 @@ NOTE. In Rails 3.1 the +jquery-rails+ gem provides the +jquery.js+ and +jquery_u
The +require_tree+ directive tells Sprockets to recursively include _all_ JavaScript files in this directory into the output. Only a path relative to the manifest file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting).
-Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output.
+Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular order among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output.
There's also a default +app/assets/stylesheets/application.css+ file which contains these lines:
--
cgit v1.2.3
From 9f74ce29245c1a0ffe51e7e6af3d45871b275870 Mon Sep 17 00:00:00 2001
From: Justin Leitgeb
Date: Tue, 27 Sep 2011 18:45:21 -0400
Subject: Make case in configuration document consistent
---
railties/guides/source/configuring.textile | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 41b53440f7..ce1d759d5b 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -179,16 +179,16 @@ h4. Configuring Middleware
Every Rails application comes with a standard set of middleware which it uses in this order in the development environment:
-* +Rack::SSL+ Will force every request to be under HTTPS protocol. Will be available if +config.force_ssl+ is set to +true+. Options passed to this can be configured by using +config.ssl_options+.
+* +Rack::SSL+ forces every request to be under HTTPS protocol. Will be available if +config.force_ssl+ is set to +true+. Options passed to this can be configured by using +config.ssl_options+.
* +ActionDispatch::Static+ is used to serve static assets. Disabled if +config.serve_static_assets+ is +true+.
-* +Rack::Lock+ Will wrap the app in mutex so it can only be called by a single thread at a time. Only enabled if +config.action_controller.allow_concurrency+ is set to +false+, which it is by default.
-* +ActiveSupport::Cache::Strategy::LocalCache+ Serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
-* +Rack::Runtime+ Sets an +X-Runtime+ header, containing the time (in seconds) taken to execute the request.
-* +Rails::Rack::Logger+ Notifies the logs that the request has began. After request is complete, flushes all the logs.
-* +ActionDispatch::ShowExceptions+ Rescues any exception returned by the application and renders nice exception pages if the request is local or if +config.consider_all_requests_local+ is set to +true+. If +config.action_dispatch.show_exceptions+ is set to +false+, exceptions will be raised regardless.
-* +ActionDispatch::RemoteIp+ Checks for IP spoofing attacks. Configurable with the +config.action_dispatch.ip_spoofing_check+ and +config.action_dispatch.trusted_proxies+ settings.
-* +Rack::Sendfile+ Intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with +config.action_dispatch.x_sendfile_header+.
-* +ActionDispatch::Callbacks+ Runs the prepare callbacks before serving the request.
+* +Rack::Lock+ wraps the app in mutex so it can only be called by a single thread at a time. Only enabled if +config.action_controller.allow_concurrency+ is set to +false+, which it is by default.
+* +ActiveSupport::Cache::Strategy::LocalCache+ serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
+* +Rack::Runtime+ sets an +X-Runtime+ header, containing the time (in seconds) taken to execute the request.
+* +Rails::Rack::Logger+ notifies the logs that the request has began. After request is complete, flushes all the logs.
+* +ActionDispatch::ShowExceptions+ rescues any exception returned by the application and renders nice exception pages if the request is local or if +config.consider_all_requests_local+ is set to +true+. If +config.action_dispatch.show_exceptions+ is set to +false+, exceptions will be raised regardless.
+* +ActionDispatch::RemoteIp+ checks for IP spoofing attacks. Configurable with the +config.action_dispatch.ip_spoofing_check+ and +config.action_dispatch.trusted_proxies+ settings.
+* +Rack::Sendfile+ intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with +config.action_dispatch.x_sendfile_header+.
+* +ActionDispatch::Callbacks+ runs the prepare callbacks before serving the request.
* +ActiveRecord::ConnectionAdapters::ConnectionManagement+ cleans active connections after each request, unless the +rack.test+ key in the request environment is set to +true+.
* +ActiveRecord::QueryCache+ caches all SELECT queries generated in a request. If any INSERT or UPDATE takes place then the cache is cleaned.
* +ActionDispatch::Cookies+ sets cookies for the request.
--
cgit v1.2.3
From 0678a5bb18b7045054a03bbe2ca0434486a7d404 Mon Sep 17 00:00:00 2001
From: Michael Hutchinson
Date: Tue, 27 Sep 2011 18:11:01 -0700
Subject: Corrected a typo.
---
railties/guides/source/active_record_querying.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 96f91cfef6..b1acdd189a 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -616,7 +616,7 @@ c1.first_name = "Michael"
c1.save
c2.name = "should fail"
-c2.save # Raises a ActiveRecord::StaleObjectError
+c2.save # Raises an ActiveRecord::StaleObjectError
You're then responsible for dealing with the conflict by rescuing the exception and either rolling back, merging, or otherwise apply the business logic needed to resolve the conflict.
--
cgit v1.2.3
From f3b8cd9d364934795ee4ec63a2d8852b3dde1aa8 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 28 Sep 2011 13:35:46 +0530
Subject: fixing typo in assets guide
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 8a15618eb2..152f42f4eb 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -219,7 +219,7 @@ NOTE. In Rails 3.1 the +jquery-rails+ gem provides the +jquery.js+ and +jquery_u
The +require_tree+ directive tells Sprockets to recursively include _all_ JavaScript files in this directory into the output. Only a path relative to the manifest file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting).
-Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular order among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output.
+Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unspecified. You should not rely on any particular order among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output.
There's also a default +app/assets/stylesheets/application.css+ file which contains these lines:
--
cgit v1.2.3
From 4535191c61b496b1a5e9dc57624581753fa71497 Mon Sep 17 00:00:00 2001
From: Ryan Oblak
Date: Tue, 27 Sep 2011 22:39:31 -0700
Subject: Modified String#pluralize to take an optional count parameter.
---
railties/guides/source/active_support_core_extensions.textile | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 5aee001545..153a897b1c 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1426,6 +1426,14 @@ The method +pluralize+ returns the plural of its receiver:
As the previous example shows, Active Support knows some irregular plurals and uncountable nouns. Built-in rules can be extended in +config/initializers/inflections.rb+. That file is generated by the +rails+ command and has instructions in comments.
++pluralize+ can also take an optional +count+ parameter. If count == 1 the singular form will be returned. For any other value of +count+ the plural form will be returned:
+
+
+"dude".pluralize(0) # => "dudes"
+"dude".pluralize(1) # => "dude"
+"dude".pluralize(2) # => "dudes"
+
+
Active Record uses this method to compute the default table name that corresponds to a model:
--
cgit v1.2.3
From cba3c00831a7c5bb25bc785e856984705ca2077c Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Wed, 28 Sep 2011 13:48:23 -0700
Subject: partial pass over the assets guide
---
railties/guides/source/asset_pipeline.textile | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 152f42f4eb..a0af018d30 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -261,7 +261,7 @@ h3. In Development
In development mode assets are served as separate files in the order they are specified in the manifest file.
-This manifest +application.js+:
+This manifest +app/assets/javascripts/application.js+:
//= require core
@@ -272,45 +272,42 @@ This manifest +application.js+:
would generate this HTML:
-
-
-
+
+
+
The +body+ param is required by Sprockets.
h4. Turning Debugging off
-You can turn off debug mode by updating +development.rb+ to include:
+You can turn off debug mode by updating +config/environments/development.rb+ to include:
-
+
config.assets.debug = false
-
+
-When debug mode is off Sprockets will concatenate and run the necessary preprocessors on all files, generating the following HTML:
+When debug mode is off Sprockets concatenates and runs the necessary preprocessors on all files. With debug mode turned off the manifest above would generate instead:
-
+
-Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response.
+Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (Not Modified) response.
If any of the files in the manifest have changed between requests, the server responds with a new compiled file.
-You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render individual tags for each file. This is useful for tracking down exact line numbers when debugging.
-
-Debug can also be set in the Rails helper methods:
+Debug mode can also be enabled in the Rails helper methods:
<%= stylesheet_link_tag "application", :debug => true %>
<%= javascript_include_tag "application", :debug => true %>
-The +:debug+ option is ignored if the debug mode is off.
+The +:debug+ option is redundant if debug mode is on.
You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging.
-
h3. In Production
In the production environment Rails uses the fingerprinting scheme outlined above. By default it is assumed that assets have been precompiled and will be served as static assets by your web server.
--
cgit v1.2.3
From 409268edfc3aa1e2df1cd0cb5acb720ce98ace89 Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Fri, 30 Sep 2011 23:28:51 +0100
Subject: Small typo corrected.
---
railties/guides/source/getting_started.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 33f383f173..23d55e6bba 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -360,7 +360,7 @@ development:
h5. Configuring an SQLite3 Database for JRuby Platform
-If you choose to use SQLite3 and using JRuby, your +config/database.yml+ will
+If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will
look a little different. Here's the development section:
@@ -371,7 +371,7 @@ development:
h5. Configuring a MySQL Database for JRuby Platform
-If you choose to use MySQL and using JRuby, your +config/database.yml+ will look
+If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look
a little different. Here's the development section:
@@ -384,7 +384,7 @@ development:
h5. Configuring a PostgreSQL Database for JRuby Platform
-Finally if you choose to use PostgreSQL and using JRuby, your
+Finally if you choose to use PostgreSQL and are using JRuby, your
+config/database.yml+ will look a little different. Here's the development
section:
--
cgit v1.2.3
From 059c04d4dd20412e63e691277069b456fc8951ab Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Sat, 1 Oct 2011 11:39:00 +0100
Subject: Several small corrections and clarifications.
---
railties/guides/source/getting_started.textile | 60 +++++++++++++-------------
1 file changed, 31 insertions(+), 29 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 23d55e6bba..7f0a3d376e 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -599,7 +599,7 @@ The above migration creates a method named +change+ which will be called when yo
run this migration. The action defined in that method is also reversible, which
means Rails knows how to reverse the change made by this migration, in case you
want to reverse it at later date. By default, when you run this migration it
-will creates a +posts+ table with two string columns and a text column. It also
+creates a +posts+ table with two string columns and a text column. It also
creates two timestamp fields to track record creation and updating. More
information about Rails migrations can be found in the "Rails Database
Migrations":migrations.html guide.
@@ -620,9 +620,9 @@ table.
== CreatePosts: migrated (0.0020s) ===========================================
-NOTE. Because you're working in the development environment by default, this
+NOTE. Because by default you're working in the development environment, this
command will apply to the database defined in the +development+ section of your
-+config/database.yml+ file. If you would like to execute migrations in other
++config/database.yml+ file. If you would like to execute migrations in another
environment, for instance in production, you must explicitly pass it when
invoking the command: rake db:migrate RAILS_ENV=production.
@@ -704,8 +704,8 @@ $ rails console
TIP: The default console will make changes to your database. You can instead
-open a console that will roll back any changes you make by using +rails console
---sandbox+.
+open a console that will roll back any changes you make by using rails console
+--sandbox .
After the console loads, you can use it to work with your application's models:
@@ -783,7 +783,8 @@ Here's +app/views/posts/index.html.erb+:
<%= post.content %>
<%= link_to 'Show', post %>
<%= link_to 'Edit', edit_post_path(post) %>
-
<%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %>
+
<%= link_to 'Destroy', post, :confirm => 'Are you sure?',
+ :method => :delete %>
<% end %>
@@ -867,10 +868,10 @@ The +new.html.erb+ view displays this empty Post to the user:
The +<%= render 'form' %>+ line is our first introduction to _partials_ in
Rails. A partial is a snippet of HTML and Ruby code that can be reused in
-multiple locations. In this case, the form used to make a new post, is basically
-identical to a form used to edit a post, both have text fields for the name and
-title and a text area for the content with a button to make a new post or update
-the existing post.
+multiple locations. In this case, the form used to make a new post is basically
+identical to the form used to edit a post, both having text fields for the name and
+title, a text area for the content, and a button to create the new post or to update
+the existing one.
If you take a look at +views/posts/_form.html.erb+ file, you will see the
following:
@@ -879,7 +880,8 @@ following:
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
-
<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:
+
<%= pluralize(@post.errors.count, "error") %> prohibited
+ this post from being saved:
<% @post.errors.full_messages.each do |msg| %>
<%= msg %>
@@ -907,15 +909,15 @@ following:
This partial receives all the instance variables defined in the calling view
-file, so in this case, the controller assigned the new Post object to +@post+
-and so, this is available in both the view and partial as +@post+.
+file. In this case, the controller assigned the new +Post+ object to +@post+,
+which will thus be available in both the view and the partial as +@post+.
For more information on partials, refer to the "Layouts and Rendering in
Rails":layouts_and_rendering.html#using-partials guide.
The +form_for+ block is used to create an HTML form. Within this block, you have
access to methods to build various controls on the form. For example,
-+f.text_field :name+ tells Rails to create a text input on the form, and to hook
++f.text_field :name+ tells Rails to create a text input on the form and to hook
it up to the +name+ attribute of the instance being displayed. You can only use
these methods with attributes of the model that the form is based on (in this
case +name+, +title+, and +content+). Rails uses +form_for+ in preference to
@@ -931,9 +933,9 @@ to a model, you should use the +form_tag+ method, which provides shortcuts for
building forms that are not necessarily tied to a model instance.
When the user clicks the +Create Post+ button on this form, the browser will
-send information back to the +create+ method of the controller (Rails knows to
-call the +create+ method because the form is sent with an HTTP POST request;
-that's one of the conventions that I mentioned earlier):
+send information back to the +create+ action of the controller (Rails knows to
+call the +create+ action because the form is sent with an HTTP POST request;
+that's one of the conventions that were mentioned earlier):
def create
@@ -965,12 +967,12 @@ If the post was not successfully saved, due to a validation error, then the
controller returns the user back to the +new+ action with any error messages so
that the user has the chance to fix the error and try again.
-The "Post was successfully created." message is stored inside of the Rails
-+flash+ hash, (usually just called _the flash_) so that messages can be carried
+The "Post was successfully created." message is stored in the Rails
++flash+ hash (usually just called _the flash_), so that messages can be carried
over to another action, providing the user with useful information on the status
of their request. In the case of +create+, the user never actually sees any page
-rendered during the Post creation process, because it immediately redirects to
-the new Post as soon Rails saves the record. The Flash carries over a message to
+rendered during the post creation process, because it immediately redirects to
+the new +Post+ as soon as Rails saves the record. The Flash carries over a message to
the next action, so that when the user is redirected back to the +show+ action,
they are presented with a message saying "Post was successfully created."
@@ -1043,9 +1045,9 @@ it:
<%= link_to 'Back', posts_path %>
-Again, as with the +new+ action, the +edit+ action is using the +form+ partial,
-this time however, the form will do a PUT action to the PostsController and the
-submit button will display "Update Post"
+Again, as with the +new+ action, the +edit+ action is using the +form+ partial.
+This time, however, the form will do a PUT action to the +PostsController+ and the
+submit button will display "Update Post".
Submitting the form created by this view will invoke the +update+ action within
the controller:
@@ -1070,9 +1072,9 @@ end
In the +update+ action, Rails first uses the +:id+ parameter passed back from
the edit view to locate the database record that's being edited. The
-+update_attributes+ call then takes the rest of the parameters from the request
-and applies them to this record. If all goes well, the user is redirected to the
-post's +show+ view. If there are any problems, it's back to the +edit+ view to
++update_attributes+ call then takes the +post+ parameter (a hash) from the request
+and applies it to this record. If all goes well, the user is redirected to the
+post's +show+ action. If there are any problems, it's back to the +edit+ action to
correct them.
h4. Destroying a Post
@@ -1094,8 +1096,8 @@ end
The +destroy+ method of an Active Record model instance removes the
corresponding record from the database. After that's done, there isn't any
-record to display, so Rails redirects the user's browser to the index view for
-the model.
+record to display, so Rails redirects the user's browser to the index action of
+the controller.
h3. Adding a Second Model
--
cgit v1.2.3
From a917c2ba8b669a1644a1df2a0002cb4676388dc7 Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Sat, 1 Oct 2011 12:48:34 +0100
Subject: Several other small corrections.
---
railties/guides/source/getting_started.textile | 61 +++++++++++++-------------
1 file changed, 31 insertions(+), 30 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 7f0a3d376e..6812b6b9fe 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1109,19 +1109,20 @@ h4. Generating a Model
Models in Rails use a singular name, and their corresponding database tables use
a plural name. For the model to hold comments, the convention is to use the name
-Comment. Even if you don't want to use the entire apparatus set up by
++Comment+. Even if you don't want to use the entire apparatus set up by
scaffolding, most Rails developers still use generators to make things like
models and controllers. To create the new model, run this command in your
terminal:
-$ rails generate model Comment commenter:string body:text post:references
+$ rails generate model Comment commenter:string body:text \
+> post:references
This command will generate four files:
-* +app/models/comment.rb+ - The model
-* +db/migrate/20100207235629_create_comments.rb+ - The migration
+* +app/models/comment.rb+ - The model.
+* +db/migrate/20100207235629_create_comments.rb+ - The migration.
* +test/unit/comment_test.rb+ and +test/fixtures/comments.yml+ - The test harness.
First, take a look at +comment.rb+:
@@ -1179,8 +1180,8 @@ Active Record associations let you easily declare the relationship between two
models. In the case of comments and posts, you could write out the relationships
this way:
-* Each comment belongs to one post
-* One post can have many comments
+* Each comment belongs to one post.
+* One post can have many comments.
In fact, this is very close to the syntax that Rails uses to declare this
association. You've already seen the line of code inside the Comment model that
@@ -1206,7 +1207,7 @@ end
These two declarations enable a good bit of automatic behavior. For example, if
you have an instance variable +@post+ containing a post, you can retrieve all
-the comments belonging to that post as the array +@post.comments+.
+the comments belonging to that post as an array using +@post.comments+.
TIP: For more information on Active Record associations, see the "Active Record
Associations":association_basics.html guide.
@@ -1215,9 +1216,9 @@ h4. Adding a Route for Comments
As with the +home+ controller, we will need to add a route so that Rails knows
where we would like to navigate to see +comments+. Open up the
-+config/routes.rb+ file again, you will see an entry that was added
-automatically for +posts+ near the top by the scaffold generator, +resources
-:posts+, edit it as follows:
++config/routes.rb+ file again. Near the top, you will see the entry for +posts+
+that was added automatically by the scaffold generator: resources
+:posts. Edit it as follows:
resources :posts do
@@ -1243,19 +1244,19 @@ $ rails generate controller Comments
This creates six files and one empty directory:
-* +app/controllers/comments_controller.rb+ - The controller
-* +app/helpers/comments_helper.rb+ - A view helper file
-* +test/functional/comments_controller_test.rb+ - The functional tests for the controller
-* +test/unit/helpers/comments_helper_test.rb+ - The unit tests for the helper
-* +app/views/comments/+ - Views of the controller are stored here
-* +app/assets/stylesheets/comment.css.scss+ - Cascading style sheet for the controller
-* +app/assets/javascripts/comment.js.coffee+ - CoffeeScript for the controller
+* +app/controllers/comments_controller.rb+ - The controller.
+* +app/helpers/comments_helper.rb+ - A view helper file.
+* +test/functional/comments_controller_test.rb+ - The functional tests for the controller.
+* +test/unit/helpers/comments_helper_test.rb+ - The unit tests for the helper.
+* +app/views/comments/+ - Views of the controller are stored here.
+* +app/assets/stylesheets/comment.css.scss+ - Cascading style sheet for the controller.
+* +app/assets/javascripts/comment.js.coffee+ - CoffeeScript for the controller.
Like with any blog, our readers will create their comments directly after
reading the post, and once they have added their comment, will be sent back to
the post show page to see their comment now listed. Due to this, our
+CommentsController+ is there to provide a method to create comments and delete
-SPAM comments when they arrive.
+spam comments when they arrive.
So first, we'll wire up the Post show template
(+/app/views/posts/show.html.erb+) to let us make a new comment:
@@ -1297,8 +1298,8 @@ So first, we'll wire up the Post show template
<%= link_to 'Back to Posts', posts_path %> |
-This adds a form on the Post show page that creates a new comment, which will
-call the +CommentsController+ +create+ action, so let's wire that up:
+This adds a form on the +Post+ show page that creates a new comment by
+calling the +CommentsController+ +create+ action. Let's wire that up:
class CommentsController < ApplicationController
@@ -1311,9 +1312,9 @@ end
You'll see a bit more complexity here than you did in the controller for posts.
-That's a side-effect of the nesting that you've set up; each request for a
+That's a side-effect of the nesting that you've set up. Each request for a
comment has to keep track of the post to which the comment is attached, thus the
-initial find action to the Post model to get the post in question.
+initial call to the +find+ method of the +Post+ model to get the post in question.
In addition, the code takes advantage of some of the methods available for an
association. We use the +create+ method on +@post.comments+ to create and save
@@ -1383,9 +1384,9 @@ right places.
h3. Refactoring
-Now that we have Posts and Comments working, if we take a look at the
-+app/views/posts/show.html.erb+ template, it's getting long and awkward. We can
-use partials to clean this up.
+Now that we have posts and comments working, take a look at the
++app/views/posts/show.html.erb+ template. It is getting long and awkward. We can
+use partials to clean it up.
h4. Rendering Partial Collections
@@ -1405,7 +1406,7 @@ following into it:
-Then in the +app/views/posts/show.html.erb+ you can change it to look like the
+Then you can change +app/views/posts/show.html.erb+ to look like the
following:
@@ -1458,8 +1459,8 @@ comment to a local variable named the same as the partial, in this case
h4. Rendering a Partial Form
-Let's also move that new comment section out to its own partial. Again, you
-create a file +app/views/comments/_form.html.erb+ and in it you put:
+Let us also move that new comment section out to its own partial. Again, you
+create a file +app/views/comments/_form.html.erb+ containing:
<%= form_for([@post, @post.comments.build]) do |f| %>
@@ -1510,7 +1511,7 @@ Then you make the +app/views/posts/show.html.erb+ look like the following:
The second render just defines the partial template we want to render,
-comments/form, Rails is smart enough to spot the forward slash in that
+comments/form. Rails is smart enough to spot the forward slash in that
string and realize that you want to render the _form.html.erb file in
the app/views/comments directory.
@@ -1519,7 +1520,7 @@ defined it as an instance variable.
h3. Deleting Comments
-Another important feature on a blog is being able to delete SPAM comments. To do
+Another important feature of a blog is being able to delete SPAM comments. To do
this, we need to implement a link of some sort in the view and a +DELETE+ action
in the +CommentsController+.
--
cgit v1.2.3
From 6e00c05607c03eead00966a5de4769b2e77af196 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Sun, 2 Oct 2011 11:35:41 -0700
Subject: documents config.assets.initialize_on_precompile in the asset
pipeline guide
---
railties/guides/source/asset_pipeline.textile | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index a0af018d30..da0ffb80d2 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -346,6 +346,13 @@ The rake task is:
bundle exec rake assets:precompile
+Asset templates in general have access to application objects. You may prevent application
+initialization in precompilation setting +config.assets.initialize_on_precompile+ to false.
+
+WARNING: Application objects may still be in scope in asset templates in develoment mode.
+If +config.assets.initialize_on_precompile+ is set to false it is your responsability not
+to use them at all.
+
Capistrano (v2.8.0 and above) has a recipe to handle this in deployment. Add the following line to +Capfile+:
--
cgit v1.2.3
From ac1fc5c59499db8d3e875bbd76e0b7c2c9240089 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Sun, 2 Oct 2011 12:33:14 -0700
Subject: rewords the docs of config.assets.initialize_on_precompile in the
asset pipeline guide
---
railties/guides/source/asset_pipeline.textile | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index da0ffb80d2..7795b297f3 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -346,12 +346,14 @@ The rake task is:
bundle exec rake assets:precompile
-Asset templates in general have access to application objects. You may prevent application
-initialization in precompilation setting +config.assets.initialize_on_precompile+ to false.
-
-WARNING: Application objects may still be in scope in asset templates in develoment mode.
-If +config.assets.initialize_on_precompile+ is set to false it is your responsability not
-to use them at all.
+For faster asset precompiles, you can partially load your application by setting
++config.assets.initialize_on_precompile+ to false, though in that case templates
+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
+test +rake assets:precompile+ locally before deploying. It may expose bugs where
+your assets reference application objects or methods, since those are still
+in scope in development mode regardless of the value of this flag.
Capistrano (v2.8.0 and above) has a recipe to handle this in deployment. Add the following line to +Capfile+:
--
cgit v1.2.3
From e3d4603151db945ebab950c1f5095e29e6369b11 Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Mon, 3 Oct 2011 14:47:24 +0100
Subject: Several small corrections and improvements to the Migrations and
Active Record Basics guides.
---
.../guides/source/active_record_basics.textile | 57 ++++++++++----------
railties/guides/source/migrations.textile | 62 +++++++++++-----------
2 files changed, 59 insertions(+), 60 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_basics.textile b/railties/guides/source/active_record_basics.textile
index cab8c80866..66ad7b0255 100644
--- a/railties/guides/source/active_record_basics.textile
+++ b/railties/guides/source/active_record_basics.textile
@@ -38,47 +38,48 @@ When writing applications using other programming languages or frameworks, it ma
h4. Naming Conventions
-By default, Active Record uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class +Book+, you should have a database table called *books*. The Rails pluralization mechanisms are very powerful, being capable to pluralize (and singularize) both regular and irregular words. When using class names composed of two or more words, the model class name should follow the Ruby conventions, using the camelCase form, while the table name must contain the words separated by underscores. Examples:
+By default, Active Record uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class +Book+, you should have a database table called *books*. The Rails pluralization mechanisms are very powerful, being capable to pluralize (and singularize) both regular and irregular words. When using class names composed of two or more words, the model class name should follow the Ruby conventions, using the CamelCase form, while the table name must contain the words separated by underscores. Examples:
-* Database Table - Plural with underscores separating words (e.g., book_clubs)
-* Model Class - Singular with the first letter of each word capitalized (e.g., BookClub)
+* Database Table - Plural with underscores separating words (e.g., +book_clubs+)
+* Model Class - Singular with the first letter of each word capitalized (e.g., +BookClub+)
|_.Model / Class |_.Table / Schema |
-|Post |posts|
-|LineItem |line_items|
-|Deer |deer|
-|Mouse |mice|
-|Person |people|
+|+Post+ |+posts+|
+|+LineItem+ |+line_items+|
+|+Deer+ |+deer+|
+|+Mouse+ |+mice+|
+|+Person+ |+people+|
h4. Schema Conventions
Active Record uses naming conventions for the columns in database tables, depending on the purpose of these columns.
-* *Foreign keys* - These fields should be named following the pattern table_id (e.g., item_id, order_id). These are the fields that Active Record will look for when you create associations between your models.
-* *Primary keys* - By default, Active Record will use an integer column named "id" as the table's primary key. When using "Rails Migrations":migrations.html to create your tables, this column will be automatically created.
+* *Foreign keys* - These fields should be named following the pattern +singularized_table_name_id+ (e.g., +item_id+, +order_id+). These are the fields that Active Record will look for when you create associations between your models.
+* *Primary keys* - By default, Active Record will use an integer column named +id+ as the table's primary key. When using "Rails Migrations":migrations.html to create your tables, this column will be automatically created.
There are also some optional column names that will create additional features to Active Record instances:
-* *created_at* - Automatically gets set to the current date and time when the record is first created.
-* *created_on* - Automatically gets set to the current date when the record is first created.
-* *updated_at* - Automatically gets set to the current date and time whenever the record is updated.
-* *updated_on* - Automatically gets set to the current date whenever the record is updated.
-* *lock_version* - Adds "optimistic locking":http://api.rubyonrails.org/classes/ActiveRecord/Locking.html to a model.
-* *type* - Specifies that the model uses "Single Table Inheritance":http://api.rubyonrails.org/classes/ActiveRecord/Base.html
-* *(table_name)_count* - Used to cache the number of belonging objects on associations. For example, a +comments_count+ column in a +Post+ class that has many instances of +Comment+ will cache the number of existent comments for each post.
+* +created_at+ - Automatically gets set to the current date and time when the record is first created.
+* +created_on+ - Automatically gets set to the current date when the record is first created.
+* +updated_at+ - Automatically gets set to the current date and time whenever the record is updated.
+* +updated_on+ - Automatically gets set to the current date whenever the record is updated.
+* +lock_version+ - Adds "optimistic locking":http://api.rubyonrails.org/classes/ActiveRecord/Locking.html to a model.
+* +type+ - Specifies that the model uses "Single Table Inheritance":http://api.rubyonrails.org/classes/ActiveRecord/Base.html
+* +(table_name)_count+ - Used to cache the number of belonging objects on associations. For example, a +comments_count+ column in a +Post+ class that has many instances of +Comment+ will cache the number of existent comments for each post.
-NOTE: While these column names are optional they are in fact reserved by Active Record. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling.
+NOTE: While these column names are optional, they are in fact reserved by Active Record. Steer clear of reserved keywords unless you want the extra functionality. For example, +type+ is a reserved keyword used to designate a table using Single Table Inheritance (STI). If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling.
h3. Creating Active Record Models
-It's very easy to create Active Record models. All you have to do is to subclass the +ActiveRecord::Base+ class and you're good to go:
+It is very easy to create Active Record models. All you have to do is to subclass the +ActiveRecord::Base+ class and you're good to go:
-class Product < ActiveRecord::Base; end
+class Product < ActiveRecord::Base
+end
-This will create a +Product+ model, mapped to a *products* table at the database. By doing this you'll also have the ability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the *products* table was created using an SQL sentence like:
+This will create a +Product+ model, mapped to a +products+ table at the database. By doing this you'll also have the ability to map the columns of each row in that table with the attributes of the instances of your model. Suppose that the +products+ table was created using an SQL sentence like:
CREATE TABLE products (
@@ -126,21 +127,21 @@ class Product < ActiveRecord::Base
end
-h3. Reading and Writing Data
+h3. CRUD: Reading and Writing Data
CRUD is an acronym for the four verbs we use to operate on data: *C*reate, *R*ead, *U*pdate and *D*elete. Active Record automatically creates methods to allow an application to read and manipulate data stored within its tables.
h4. Create
-Active Record objects can be created from a hash, a block or have its attributes manually set after creation. The _new_ method will return a new object while _create_ will return the object and save it to the database.
+Active Record objects can be created from a hash, a block or have their attributes manually set after creation. The +new+ method will return a new object while +create+ will return the object and save it to the database.
-For example, given a model +User+ with attributes of +name+ and +occupation+, the _create_ method call will create and save a new record into the database:
+For example, given a model +User+ with attributes of +name+ and +occupation+, the +create+ method call will create and save a new record into the database:
user = User.create(:name => "David", :occupation => "Code Artist")
-Using the _new_ method, an object can be created without being saved:
+Using the +new+ method, an object can be created without being saved:
user = User.new
@@ -148,9 +149,9 @@ Using the _new_ method, an object can be created without being saved:
user.occupation = "Code Artist"
-A call to _user.save_ will commit the record to the database.
+A call to +user.save+ will commit the record to the database.
-Finally, passing a block to either create or new will return a new User object:
+Finally, if a block is provided, both +create+ and +new+ will yield the new object to that block for initialization:
user = User.new do |u|
@@ -164,7 +165,7 @@ h4. Read
Active Record provides a rich API for accessing data within a database. Below are a few examples of different data access methods provided by Active Record.
- # return all records
+ # return array with all records
users = User.all
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 7faa18e888..a73655d130 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -91,13 +91,13 @@ Active Record provides methods that perform common data definition tasks in a da
* +add_index+
* +remove_index+
-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).
+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+ method 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 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
-Migrations are stored in files in +db/migrate+, one for each migration class. The name of the file is of the form +YYYYMMDDHHMMSS_create_products.rb+, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The name of the migration class (CamelCased version) should match the latter part of the file name. For example +20080906120000_create_products.rb+ should define +CreateProducts+ and +20080906120001_add_details_to_products.rb+ should define +AddDetailsToProducts+. If you do feel the need to change the file name then you have to update the name of the class inside or Rails will complain about a missing class.
+Migrations are stored in files in +db/migrate+, one for each migration class. The name of the file is of the form +YYYYMMDDHHMMSS_create_products.rb+, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The name of the migration class (CamelCased version) should match the latter part of the file name. For example +20080906120000_create_products.rb+ should define class +CreateProducts+ and +20080906120001_add_details_to_products.rb+ should define +AddDetailsToProducts+. If you do feel the need to change the file name then you have to update the name of the class inside or Rails will complain about a missing class.
Internally Rails only uses the migration's number (the timestamp) to identify them. Prior to Rails 2.1 the migration number started at 1 and was incremented each time a migration was generated. With multiple developers it was easy for these to clash requiring you to rollback migrations and renumber them. With Rails 2.1 this is largely avoided by using the creation time of the migration to identify them. You can revert to the old numbering scheme by adding the following line to +config/application.rb+.
@@ -115,7 +115,7 @@ h4. Changing Migrations
Occasionally you will make a mistake when writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run +rake db:migrate+. You must rollback the migration (for example with +rake db:rollback+), edit your migration and then run +rake db:migrate+ to run the corrected version.
-In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless.
+In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead, you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or, more generally, which has not been propagated beyond your development machine) is relatively harmless.
h4. Supported Types
@@ -134,7 +134,7 @@ Active Record supports the following types:
* +:binary+
* +:boolean+
-These will be mapped onto an appropriate underlying database type, for example with MySQL +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example
+These will be mapped onto an appropriate underlying database type. For example, with MySQL the type +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example
create_table :products do |t|
@@ -148,7 +148,7 @@ h3. Creating a Migration
h4. Creating a Model
-The model and scaffold generators will create migrations appropriate for adding a new model. This migration will already contain instructions for creating the relevant table. If you tell Rails what columns you want then statements for adding those will also be created. For example, running
+The model and scaffold generators will create migrations appropriate for adding a new model. This migration will already contain instructions for creating the relevant table. If you tell Rails what columns you want, then statements for adding these columns will also be created. For example, running
$ rails generate model Product name:string description:text
@@ -262,7 +262,7 @@ end
which creates a +products+ table with a column called +name+ (and as discussed below, an implicit +id+ column).
-The object yielded to the block allows you to create columns on the table. There are two ways of doing this: The first (traditional) form looks like
+The object yielded to the block allows you to create columns on the table. There are two ways of doing it. The first (traditional) form looks like
create_table :products do |t|
@@ -270,7 +270,7 @@ create_table :products do |t|
end
-the second form, the so called "sexy" migration, drops the somewhat redundant +column+ method. Instead, the +string+, +integer+, etc. methods create a column of that type. Subsequent parameters are the same.
+The second form, the so called "sexy" migration, drops the somewhat redundant +column+ method. Instead, the +string+, +integer+, etc. methods create a column of that type. Subsequent parameters are the same.
create_table :products do |t|
@@ -278,7 +278,7 @@ create_table :products do |t|
end
-By default +create_table+ will create a primary key called +id+. You can change the name of the primary key with the +:primary_key+ option (don't forget to update the corresponding model) or if you don't want a primary key at all (for example for a HABTM join table) you can pass +:id => false+. If you need to pass database specific options you can place an SQL fragment in the +:options+ option. For example
+By default, +create_table+ will create a primary key called +id+. You can change the name of the primary key with the +:primary_key+ option (don't forget to update the corresponding model) or, if you don't want a primary key at all (for example for a HABTM join table), you can pass the option +:id => false+. If you need to pass database specific options you can place an SQL fragment in the +:options+ option. For example,
create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
@@ -286,7 +286,7 @@ create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
end
-will append +ENGINE=BLACKHOLE+ to the SQL statement used to create the table (when using MySQL the default is +ENGINE=InnoDB+).
+will append +ENGINE=BLACKHOLE+ to the SQL statement used to create the table (when using MySQL, the default is +ENGINE=InnoDB+).
h4. Changing Tables
@@ -348,11 +348,11 @@ end
will add an +attachment_id+ column and a string +attachment_type+ column with a default value of 'Photo'.
-NOTE: The +references+ helper does not actually create foreign key constraints for you. You will need to use +execute+ for that or a plugin that adds "foreign key support":#active-record-and-referential-integrity.
+NOTE: The +references+ helper does not actually create foreign key constraints for you. You will need to use +execute+ or a plugin that adds "foreign key support":#active-record-and-referential-integrity.
-If the helpers provided by Active Record aren't enough you can use the +execute+ function to execute arbitrary SQL.
+If the helpers provided by Active Record aren't enough you can use the +execute+ method to execute arbitrary SQL.
-For more details and examples of individual methods check the API documentation, in particular the documentation for "ActiveRecord::ConnectionAdapters::SchemaStatements":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html (which provides the methods available in the +up+ and +down+ methods), "ActiveRecord::ConnectionAdapters::TableDefinition":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html (which provides the methods available on the object yielded by +create_table+) and "ActiveRecord::ConnectionAdapters::Table":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html (which provides the methods available on the object yielded by +change_table+).
+For more details and examples of individual methods, check the API documentation, in particular the documentation for "ActiveRecord::ConnectionAdapters::SchemaStatements":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html (which provides the methods available in the +up+ and +down+ methods), "ActiveRecord::ConnectionAdapters::TableDefinition":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html (which provides the methods available on the object yielded by +create_table+) and "ActiveRecord::ConnectionAdapters::Table":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html (which provides the methods available on the object yielded by +change_table+).
h4. Writing Your +change+ Method
@@ -371,7 +371,7 @@ If you're going to use other methods, you'll have to write the +up+ and +down+ m
h4. Writing Your +down+ Method
-The +down+ method of your migration should revert the transformations done by the +up+ method. In other words the database schema should be unchanged if you do an +up+ followed by a +down+. For example if you create a table in the +up+ method you should drop it in the +down+ method. It is wise to do things in precisely the reverse order to in the +up+ method. For example
+The +down+ method of your migration should revert the transformations done by the +up+ method. In other words, the database schema should be unchanged if you do an +up+ followed by a +down+. For example, if you create a table in the +up+ method, you should drop it in the +down+ method. It is wise to reverse the transformations in precisely the reverse order they were made in the +up+ method. For example,
class ExampleMigration < ActiveRecord::Migration
@@ -402,22 +402,22 @@ class ExampleMigration < ActiveRecord::Migration
end
-Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can't reverse the migration you can raise +ActiveRecord::IrreversibleMigration+ from your +down+ method. If someone tries to revert your migration an error message will be displayed saying that it can't be done.
+Sometimes your migration will do something which is just plain irreversible; for example, it might destroy some data. In such cases, you can raise +ActiveRecord::IrreversibleMigration+ from your +down+ method. If someone tries to revert your migration, an error message will be displayed saying that it can't be done.
h3. Running Migrations
-Rails provides a set of rake tasks to work with migrations which boils down to running certain sets of migrations. The very first migration related rake task you use will probably be +db:migrate+. In its most basic form it just runs the +up+ method for all the migrations that have not yet been run. If there are no such migrations it exits.
+Rails provides a set of rake tasks to work with migrations which boil down to running certain sets of migrations. The very first migration related rake task you will use will probably be +db:migrate+. In its most basic form it just runs the +up+ method for all the migrations that have not yet been run. If there are no such migrations, it exits.
Note that running the +db:migrate+ also invokes the +db:schema:dump+ task, which will update your db/schema.rb file to match the structure of your database.
If you specify a target version, Active Record will run the required migrations (up or down) until it has reached the specified version. The
-version is the numerical prefix on the migration's filename. For example to migrate to version 20080906120000 run
+version is the numerical prefix on the migration's filename. For example, to migrate to version 20080906120000 run
$ rake db:migrate VERSION=20080906120000
-If this is greater than the current version (i.e. it is migrating upwards) this will run the +up+ method on all migrations up to and including 20080906120000, if migrating downwards this will run the +down+ method on all the migrations down to, but not including, 20080906120000.
+If version 20080906120000 is greater than the current version (i.e., it is migrating upwards), this will run the +up+ method on all migrations up to and including 20080906120000. If migrating downwards, this will run the +down+ method on all the migrations down to, but not including, 20080906120000.
h4. Rolling Back
@@ -435,13 +435,13 @@ $ rake db:rollback STEP=3
will run the +down+ method from the last 3 migrations.
-The +db:migrate:redo+ task is a shortcut for doing a rollback and then migrating back up again. As with the +db:rollback+ task you can use the +STEP+ parameter if you need to go more than one version back, for example
+The +db:migrate:redo+ task is a shortcut for doing a rollback and then migrating back up again. As with the +db:rollback+ task, you can use the +STEP+ parameter if you need to go more than one version back, for example
$ rake db:migrate:redo STEP=3
-Neither of these Rake tasks do anything you could not do with +db:migrate+, they are simply more convenient since you do not need to explicitly specify the version to migrate to.
+Neither of these Rake tasks do anything you could not do with +db:migrate+. They are simply more convenient, since you do not need to explicitly specify the version to migrate to.
Lastly, the +db:reset+ task will drop the database, recreate it and load the current schema into it.
@@ -449,7 +449,7 @@ NOTE: This is not the same as running all the migrations - see the section on "s
h4. Being Specific
-If you need to run a specific migration up or down the +db:migrate:up+ and +db:migrate:down+ tasks will do that. Just specify the appropriate version and the corresponding migration will have its +up+ or +down+ method invoked, for example
+If you need to run a specific migration up or down, the +db:migrate:up+ and +db:migrate:down+ tasks will do that. Just specify the appropriate version and the corresponding migration will have its +up+ or +down+ method invoked, for example,
$ rake db:migrate:up VERSION=20080906120000
@@ -511,11 +511,11 @@ generates the following output
20080906170109 CreateProducts: migrated (10.0097s)
-If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress all output.
+If you just want Active Record to shut up, then running +rake db:migrate VERBOSE=false+ will suppress all output.
h3. Using Models in Your Migrations
-When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done, but some caution should be observed.
+When creating or updating data in a migration it is often tempting to use one of your models. After all, they exist to provide easy access to the underlying data. This can be done, but some caution should be observed.
For example, problems occur when the model uses database columns which are (1) not currently in the database and (2) will be created by this or a subsequent migration.
@@ -524,7 +524,7 @@ Consider this example, where Alice and Bob are working on the same code base whi
Bob goes on vacation.
Alice creates a migration for the +products+ table which adds a new column and initializes it.
-She also adds a validation to the Product model for the new column.
+She also adds a validation to the +Product+ model for the new column.
# db/migrate/20100513121110_add_flag_to_product.rb
@@ -545,7 +545,7 @@ class Product < ActiveRecord::Base
end
-Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column.
+Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the +Product+ model for the new column.
# db/migrate/20100515121110_add_fuzz_to_product.rb
@@ -573,7 +573,7 @@ Bob comes back from vacation and:
# updates the source - which contains both migrations and the latests version of the Product model.
# runs outstanding migrations with +rake db:migrate+, which includes the one that updates the +Product+ model.
-The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs.
+The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs:
rake aborted!
@@ -584,7 +584,7 @@ undefined method `fuzz' for #
A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion.
-When using a faux model, it's a good idea to call +Product.reset_column_information+ to refresh the ActiveRecord cache for the Product model prior to updating data in the database.
+When using a faux model, it's a good idea to call +Product.reset_column_information+ to refresh the +ActiveRecord+ cache for the +Product+ model prior to updating data in the database.
If Alice had done this instead, there would have been no problem:
@@ -654,13 +654,11 @@ ActiveRecord::Schema.define(:version => 20080906171750) do
end
-In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using +create_table+, +add_index+, and so on. Because this is database independent it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.
+In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using +create_table+, +add_index+, and so on. Because this is database-independent, it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.
-There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this then you should set the schema format to +:sql+.
+There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
-Instead of using Active Record's schema dumper the database's structure will be dumped using a tool specific to that database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example for PostgreSQL the +pg_dump+ utility is used and for MySQL this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading this schema is simply a question of executing the SQL statements contained inside.
-
-By definition this will be a perfect copy of the database's structure but this will usually prevent loading the schema into a database other than the one used to create it.
+Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific the RDBMS of the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
h4. Schema Dumps and Source Control
@@ -670,6 +668,6 @@ h3. Active Record and Referential Integrity
The Active Record way claims that intelligence belongs in your models, not in the database. As such, features such as triggers or foreign key constraints, which push some of that intelligence back into the database, are not heavily used.
-Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints.
+Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level, these cannot guarantee referential integrity and so some people augment them with foreign key constraints.
Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. There are also a number of plugins such as "foreign_key_migrations":https://github.com/harukizaemon/redhillonrails/tree/master/foreign_key_migrations/ which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
--
cgit v1.2.3
From 547f4af2ca34058e591f8c2912d47c562a0935ef Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Mon, 3 Oct 2011 18:03:35 +0100
Subject: Several small corrections and clarifications to the Active Record
Validations and Callbacks guide.
---
.../active_record_validations_callbacks.textile | 34 ++++++++++++----------
1 file changed, 18 insertions(+), 16 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 5c3aae2955..262ea42898 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -28,7 +28,7 @@ h4. Why Use Validations?
Validations are used to ensure that only valid data is saved into your database. For example, it may be important to your application to ensure that every user provides a valid email address and mailing address.
-There are several ways to validate data before it is saved into your database, including native database constraints, client-side validations, controller-level validations, and model-level validations.
+There are several ways to validate data before it is saved into your database, including native database constraints, client-side validations, controller-level validations, and model-level validations:
* Database constraints and/or stored procedures make the validation mechanisms database-dependent and can make testing and maintenance more difficult. However, if your database is used by other applications, it may be a good idea to use some constraints at the database level. Additionally, database-level validations can safely handle some things (such as uniqueness in heavily-used tables) that can be difficult to implement otherwise.
* Client-side validations can be useful, but are generally unreliable if used alone. If they are implemented using JavaScript, they may be bypassed if JavaScript is turned off in the user's browser. However, if combined with other techniques, client-side validation can be a convenient way to provide users with immediate feedback as they use your site.
@@ -94,7 +94,7 @@ Note that +save+ also has the ability to skip validations if passed +:validate =
h4. +valid?+ and +invalid?+
-To verify whether or not an object is valid, Rails uses the +valid?+ method. You can also use this method on your own. +valid?+ triggers your validations and returns true if no errors were added to the object, and false otherwise.
+To verify whether or not an object is valid, Rails uses the +valid?+ method. You can also use this method on your own. +valid?+ triggers your validations and returns true if no errors were found in the object, and false otherwise.
class Person < ActiveRecord::Base
@@ -105,7 +105,7 @@ Person.create(:name => "John Doe").valid? # => true
Person.create(:name => nil).valid? # => false
-When Active Record is performing validations, any errors found can be accessed through the +errors+ instance method. By definition an object is valid if this collection is empty after running validations.
+After Active Record performing validations, any errors found can be accessed through the +errors+ instance method, which returns a collection of errors. By definition an object is valid if this collection is empty after running validations.
Note that an object instantiated with +new+ will not report errors even if it's technically invalid, because validations are not run when using +new+.
@@ -139,7 +139,7 @@ end
=> ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
-+invalid?+ is simply the inverse of +valid?+. +invalid?+ triggers your validations and returns true if any errors were added to the object, and false otherwise.
++invalid?+ is simply the inverse of +valid?+. +invalid?+ triggers your validations, returning true if any errors were found in the object, and false otherwise.
h4(#validations_overview-errors). +errors[]+
@@ -160,7 +160,7 @@ We'll cover validation errors in greater depth in the "Working with Validation E
h3. Validation Helpers
-Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers provide common validation rules. Every time a validation fails, an error message is added to the object's +errors+ collection, and this message is associated with the field being validated.
+Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers provide common validation rules. Every time a validation fails, an error message is added to the object's +errors+ collection, and this message is associated with the attribute being validated.
Each helper accepts an arbitrary number of attribute names, so with a single line of code you can add the same kind of validation to several attributes.
@@ -428,6 +428,8 @@ class GoodnessValidator < ActiveModel::Validator
end
+NOTE: Errors added to +record.errors[:base]+ relate to the state of the record as a whole, and not to a specific attribute.
+
The +validates_with+ helper takes a class, or a list of classes to use for validation. There is no default error message for +validates_with+. You must manually add errors to the record's errors collection in the validator class.
To implement the validate method, you must have a +record+ parameter defined, which is the record to be validated.
@@ -454,13 +456,13 @@ This helper validates attributes against a block. It doesn't have a predefined v
class Person < ActiveRecord::Base
- validates_each :name, :surname do |model, attr, value|
- model.errors.add(attr, 'must start with upper case') if value =~ /\A[a-z]/
+ validates_each :name, :surname do |record, attr, value|
+ record.errors.add(attr, 'must start with upper case') if value =~ /\A[a-z]/
end
end
-The block receives the model, the attribute's name and the attribute's value. You can do anything you like to check for valid data within the block. If your validation fails, you can add an error message to the model, therefore making it invalid.
+The block receives the record, the attribute's name and the attribute's value. You can do anything you like to check for valid data within the block. If your validation fails, you should add an error message to the model, therefore making it invalid.
h3. Common Validation Options
@@ -580,7 +582,7 @@ Custom validators are classes that extend ActiveModel::Validator. These
class MyValidator < ActiveModel::Validator
def validate(record)
- if record.name.starts_with? 'X'
+ unless record.name.starts_with? 'X'
record.errors[:name] << 'Need a name starting with X please!'
end
end
@@ -661,7 +663,7 @@ The following is a list of the most commonly used methods. Please refer to the +
h4(#working_with_validation_errors-errors). +errors+
-Returns an OrderedHash with all errors. Each key is the attribute name and the value is an array of strings with all errors.
+Returns an instance of the class +ActiveModel::Errors+ (which behaves like an ordered hash) containing all errors. Each key is the attribute name and the value is an array of strings with all errors.
class Person < ActiveRecord::Base
@@ -741,7 +743,7 @@ Another way to do this is using +[]=+ setter
h4. +errors[:base]+
-You can add error messages that are related to the object's state as a whole, instead of being related to a specific attribute. You can use this method when you want to say that the object is invalid, no matter the values of its attributes. Since +errors[:base]+ is an array, you can simply add a string to the array and uses it as the error message.
+You can add error messages that are related to the object's state as a whole, instead of being related to a specific attribute. You can use this method when you want to say that the object is invalid, no matter the values of its attributes. Since +errors[:base]+ is an array, you can simply add a string to it and it will be used as an error message.
class Person < ActiveRecord::Base
@@ -785,7 +787,7 @@ end
person = Person.new
person.valid? # => false
-person.errors.size # => 3
+person.errors.size # => 2
person = Person.new(:name => "Andrea", :email => "andrea@example.com")
person.valid? # => true
@@ -871,10 +873,10 @@ h4. Customizing the Error Messages CSS
The selectors to customize the style of error messages are:
* +.field_with_errors+ - Style for the form fields and labels with errors.
-* +#errorExplanation+ - Style for the +div+ element with the error messages.
-* +#errorExplanation h2+ - Style for the header of the +div+ element.
-* +#errorExplanation p+ - Style for the paragraph that holds the message that appears right below the header of the +div+ element.
-* +#errorExplanation ul li+ - Style for the list items with individual error messages.
+* +#error_explanation+ - Style for the +div+ element with the error messages.
+* +#error_explanation h2+ - Style for the header of the +div+ element.
+* +#error_explanation p+ - Style for the paragraph that holds the message that appears right below the header of the +div+ element.
+* +#error_explanation ul li+ - Style for the list items with individual error messages.
Scaffolding for example generates +app/assets/stylesheets/scaffold.css.scss+, which later compiles to +app/assets/stylesheets/scaffold.css+ and defines the red-based style you saw above.
--
cgit v1.2.3
From bb4edc8edf5dd10b0c83b8920d76751fd93ffd7e Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Tue, 4 Oct 2011 16:13:16 +0100
Subject: More corrections and clarifications to the Active Record Validations
and Callbacks guide.
---
.../active_record_validations_callbacks.textile | 91 ++++++++++++----------
1 file changed, 52 insertions(+), 39 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 262ea42898..6c6f29be32 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -796,7 +796,7 @@ person.errors.size # => 0
h3. Displaying Validation Errors in the View
-Rails maintains an official plugin that provides helpers to display the error messages of your models in your view templates. You can install it as a plugin or as a Gem.
+Rails maintains an official plugin, DynamicForm, that provides helpers to display the error messages of your models in your view templates. You can install it as a plugin or as a Gem.
h4. Installing as a plugin
@@ -812,7 +812,7 @@ Add this line in your Gemfile:
gem "dynamic_form"
-Now you will have access to these two methods in your view templates.
+Now you will have access to the two help methods +error_messages+ and +error_messages_for+ in your view templates.
h4. +error_messages+ and +error_messages_for+
@@ -842,11 +842,13 @@ end
<% end %>
-To get the idea, if you submit the form with empty fields you typically get this back, though styles are indeed missing by default:
+If you submit the form with empty fields, the result will be similar to the one shown below:
!images/error_messages.png(Error messages)!
-You can also use the +error_messages_for+ helper to display the error messages of a model assigned to a view template. It's very similar to the previous example and will achieve exactly the same result.
+NOTE: The appearance of the generated HTML will be different from the one shown, unless you have used scaffolding. See "Customizing the Error Messages CSS":#customizing-error-messages-css.
+
+You can also use the +error_messages_for+ helper to display the error messages of a model assigned to a view template. It is very similar to the previous example and will achieve exactly the same result.
<%= error_messages_for :product %>
@@ -854,7 +856,7 @@ You can also use the +error_messages_for+ helper to display the error messages o
The displayed text for each error message will always be formed by the capitalized name of the attribute that holds the error, followed by the error message itself.
-Both the +form.error_messages+ and the +error_messages_for+ helpers accept options that let you customize the +div+ element that holds the messages, changing the header text, the message below the header text and the tag used for the element that defines the header.
+Both the +form.error_messages+ and the +error_messages_for+ helpers accept options that let you customize the +div+ element that holds the messages, change the header text, change the message below the header, and specify the tag used for the header element. For example,
<%= f.error_messages :header_message => "Invalid product!",
@@ -862,23 +864,23 @@ Both the +form.error_messages+ and the +error_messages_for+ helpers accept optio
:header_tag => :h3 %>
-Which results in the following content:
+results in:
!images/customized_error_messages.png(Customized error messages)!
-If you pass +nil+ to any of these options, it will get rid of the respective section of the +div+.
+If you pass +nil+ in any of these options, the corresponding section of the +div+ will be discarded.
-h4. Customizing the Error Messages CSS
+h4(#customizing-error-messages-css). Customizing the Error Messages CSS
-The selectors to customize the style of error messages are:
+The selectors used to customize the style of error messages are:
* +.field_with_errors+ - Style for the form fields and labels with errors.
* +#error_explanation+ - Style for the +div+ element with the error messages.
* +#error_explanation h2+ - Style for the header of the +div+ element.
-* +#error_explanation p+ - Style for the paragraph that holds the message that appears right below the header of the +div+ element.
+* +#error_explanation p+ - Style for the paragraph holding the message that appears right below the header of the +div+ element.
* +#error_explanation ul li+ - Style for the list items with individual error messages.
-Scaffolding for example generates +app/assets/stylesheets/scaffold.css.scss+, which later compiles to +app/assets/stylesheets/scaffold.css+ and defines the red-based style you saw above.
+If scaffolding was used, file +app/assets/stylesheets/scaffold.css.scss+ (which later compiles to +app/assets/stylesheets/scaffold.css+), will have been generated automatically. This file defines the red-based styles you saw in the examples above.
The name of the class and the id can be changed with the +:class+ and +:id+ options, accepted by both helpers.
@@ -891,7 +893,7 @@ The way form fields with errors are treated is defined by +ActionView::Base.fiel
* A string with the HTML tag
* An instance of +ActionView::Helpers::InstanceTag+.
-Here is a simple example where we change the Rails behavior to always display the error messages in front of each of the form fields with errors. The error messages will be enclosed by a +span+ element with a +validation-error+ CSS class. There will be no +div+ element enclosing the +input+ element, so we get rid of that red border around the text field. You can use the +validation-error+ CSS class to style it anyway you want.
+Below is a simple example where we change the Rails behavior to always display the error messages in front of each of the form fields in error. The error messages will be enclosed by a +span+ element with a +validation-error+ CSS class. There will be no +div+ element enclosing the +input+ element, so we get rid of that red border around the text field. You can use the +validation-error+ CSS class to style it anyway you want.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
@@ -905,17 +907,17 @@ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
end
-This will result in something like the following:
+The result look like the following:
!images/validation_error_messages.png(Validation error messages)!
h3. Callbacks Overview
-Callbacks are methods that get called at certain moments of an object's life cycle. With callbacks it's possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database.
+Callbacks are methods that get called at certain moments of an object's life cycle. With callbacks it is possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database.
h4. Callback Registration
-In order to use the available callbacks, you need to register them. You can do that by implementing them as ordinary methods, and then using a macro-style class method to register them as callbacks.
+In order to use the available callbacks, you need to register them. You can implement the callbacks as ordinary methods and use a macro-style class method to register them as callbacks:
class User < ActiveRecord::Base
@@ -932,7 +934,7 @@ class User < ActiveRecord::Base
end
-The macro-style class methods can also receive a block. Consider using this style if the code inside your block is so short that it fits in just one line.
+The macro-style class methods can also receive a block. Consider using this style if the code inside your block is so short that it fits in a single line:
class User < ActiveRecord::Base
@@ -944,7 +946,7 @@ class User < ActiveRecord::Base
end
-It's considered good practice to declare callback methods as being protected or private. If left public, they can be called from outside of the model and violate the principle of object encapsulation.
+It is considered good practice to declare callback methods as protected or private. If left public, they can be called from outside of the model and violate the principle of object encapsulation.
h3. Available Callbacks
@@ -984,7 +986,7 @@ The +after_initialize+ callback will be called whenever an Active Record object
The +after_find+ callback will be called whenever Active Record loads a record from the database. +after_find+ is called before +after_initialize+ if both are defined.
-The +after_initialize+ and +after_find+ callbacks are a bit different from the others. They have no +before_*+ counterparts, and the only way to register them is by defining them as regular methods. If you try to register +after_initialize+ or +after_find+ using macro-style class methods, they will just be ignored. This behavior is due to performance reasons, since +after_initialize+ and +after_find+ will both be called for each record found in the database, significantly slowing down the queries.
+The +after_initialize+ and +after_find+ callbacks are a bit different from the others. They have no +before_*+ counterparts, and they are registered simply by defining them as regular methods with predefined names. If you try to register +after_initialize+ or +after_find+ using macro-style class methods, they will just be ignored. This behavior is due to performance reasons, since +after_initialize+ and +after_find+ will both be called for each record found in the database, which would otherwise significantly slow down the queries.
class User < ActiveRecord::Base
@@ -1041,7 +1043,7 @@ The +after_initialize+ callback is triggered every time a new object of the clas
h3. Skipping Callbacks
-Just as with validations, it's also possible to skip callbacks. These methods should be used with caution, however, because important business rules and application logic may be kept in callbacks. Bypassing them without understanding the potential implications may lead to invalid data.
+Just as with validations, it is also possible to skip callbacks. These methods should be used with caution, however, because important business rules and application logic may be kept in callbacks. Bypassing them without understanding the potential implications may lead to invalid data.
* +decrement+
* +decrement_counter+
@@ -1060,13 +1062,13 @@ h3. Halting Execution
As you start registering new callbacks for your models, they will be queued for execution. This queue will include all your model's validations, the registered callbacks, and the database operation to be executed.
-The whole callback chain is wrapped in a transaction. If any before callback method returns exactly +false+ or raises an exception the execution chain gets halted and a ROLLBACK is issued; after callbacks can only accomplish that by raising an exception.
+The whole callback chain is wrapped in a transaction. If any before callback method returns exactly +false+ or raises an exception, the execution chain gets halted and a ROLLBACK is issued; after callbacks can only accomplish that by raising an exception.
-WARNING. Raising an arbitrary exception may break code that expects +save+ and friends not to fail like that. The +ActiveRecord::Rollback+ exception is thought precisely to tell Active Record a rollback is going on. That one is internally captured but not reraised.
+WARNING. Raising an arbitrary exception may break code that expects +save+ and its friends not to fail like that. The +ActiveRecord::Rollback+ exception is thought precisely to tell Active Record a rollback is going on. That one is internally captured but not reraised.
h3. Relational Callbacks
-Callbacks work through model relationships, and can even be defined by them. Let's take an example where a user has many posts. In our example, a user's posts should be destroyed if the user is destroyed. So, we'll add an +after_destroy+ callback to the +User+ model by way of its relationship to the +Post+ model.
+Callbacks work through model relationships, and can even be defined by them. Suppose an example where a user has many posts. A user's posts should be destroyed if the user is destroyed. Let's add an +after_destroy+ callback to the +User+ model by way of its relationship to the +Post+ model:
class User < ActiveRecord::Base
@@ -1092,11 +1094,11 @@ Post destroyed
h3. Conditional Callbacks
-Like in validations, we can also make our callbacks conditional, calling them only when a given predicate is satisfied. You can do that by using the +:if+ and +:unless+ options, which can take a symbol, a string or a +Proc+. You may use the +:if+ option when you want to specify when the callback *should* get called. If you want to specify when the callback *should not* be called, then you may use the +:unless+ option.
+As with validations, we can also make the calling of a callback method conditional on the satisfaction of a given predicate. We can do this using the +:if+ and +:unless+ options, which can take a symbol, a string or a +Proc+. You may use the +:if+ option when you want to specify under which conditions the callback *should* be called. If you want to specify the conditions under which the callback *should not* be called, then you may use the +:unless+ option.
-h4. Using +:if+ and +:unless+ with a Symbol
+h4. Using +:if+ and +:unless+ with a +Symbol+
-You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before the callback. When using the +:if+ option, the callback won't be executed if the method returns false; when using the +:unless+ option, the callback won't be executed if the method returns true. This is the most common option. Using this form of registration it's also possible to register several different methods that should be called to check if the callback should be executed.
+You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a predicate method that will get called right before the callback. When using the +:if+ option, the callback won't be executed if the predicate method returns false; when using the +:unless+ option, the callback won't be executed if the predicate method returns true. This is the most common option. Using this form of registration it is also possible to register several different predicates that should be called to check if the callback should be executed.
class Order < ActiveRecord::Base
@@ -1106,7 +1108,7 @@ end
h4. Using +:if+ and +:unless+ with a String
-You can also use a string that will be evaluated using +eval+ and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition.
+You can also use a string that will be evaluated using +eval+ and hence needs to contain valid Ruby code. You should use this option only when the string represents a really short condition:
class Order < ActiveRecord::Base
@@ -1114,9 +1116,9 @@ class Order < ActiveRecord::Base
end
-h4. Using +:if+ and +:unless+ with a Proc
+h4. Using +:if+ and +:unless+ with a +Proc+
-Finally, it's possible to associate +:if+ and +:unless+ with a +Proc+ object. This option is best suited when writing short validation methods, usually one-liners.
+Finally, it is possible to associate +:if+ and +:unless+ with a +Proc+ object. This option is best suited when writing short validation methods, usually one-liners:
class Order < ActiveRecord::Base
@@ -1127,7 +1129,7 @@ end
h4. Multiple Conditions for Callbacks
-When writing conditional callbacks, it's possible to mix both +:if+ and +:unless+ in the same callback declaration.
+When writing conditional callbacks, it is possible to mix both +:if+ and +:unless+ in the same callback declaration:
class Comment < ActiveRecord::Base
@@ -1140,7 +1142,7 @@ h3. Callback Classes
Sometimes the callback methods that you'll write will be useful enough to be reused by other models. Active Record makes it possible to create classes that encapsulate the callback methods, so it becomes very easy to reuse them.
-Here's an example where we create a class with an +after_destroy+ callback for a +PictureFile+ model.
+Here's an example where we create a class with an +after_destroy+ callback for a +PictureFile+ model:
class PictureFileCallbacks
@@ -1152,7 +1154,7 @@ class PictureFileCallbacks
end
-When declared inside a class the callback method will receive the model object as a parameter. We can now use it this way:
+When declared inside a class, as above, the callback methods will receive the model object as a parameter. We can now use the callback class in the model:
class PictureFile < ActiveRecord::Base
@@ -1160,7 +1162,7 @@ class PictureFile < ActiveRecord::Base
end
-Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we declared our callback as an instance method. Sometimes it will make more sense to have it as a class method.
+Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we declared our callback as an instance method. This is particularly useful if the callbacks make use of the state of instantiated object. Often, however, it will make more sense to declare the callbacks as class methods:
class PictureFileCallbacks
@@ -1184,16 +1186,27 @@ You can declare as many callbacks as you want inside your callback classes.
h3. Observers
-Observers are similar to callbacks, but with important differences. Whereas callbacks can pollute a model with code that isn't directly related to its purpose, observers allow you to add the same functionality outside of a model. For example, it could be argued that a +User+ model should not include code to send registration confirmation emails. Whenever you use callbacks with code that isn't directly related to your model, you may want to consider creating an observer instead.
+Observers are similar to callbacks, but with important differences. Whereas callbacks can pollute a model with code that isn't directly related to its purpose, observers allow you to add the same functionality without changing the code of the model. For example, it could be argued that a +User+ model should not include code to send registration confirmation emails. Whenever you use callbacks with code that isn't directly related to your model, you may want to consider creating an observer instead.
h4. Creating Observers
-For example, imagine a +User+ model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model's purpose, we could create an observer to contain this functionality.
+For example, imagine a +User+ model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model's purpose, we should create an observer to contain the code implementing this functionality.
+
+Rails can create the initial code of the observers in a simple way. For instance, given a model +User+, the command
$ rails generate observer User
+generates file +app/models/user_observer.rb+ containing the observer class +UserObserver+:
+
+
+class UserObserver < ActiveRecord::Observer
+end
+
+
+You may now add methods to be called at the desired occasions:
+
class UserObserver < ActiveRecord::Observer
def after_create(model)
@@ -1209,7 +1222,7 @@ h4. Registering Observers
Observers are conventionally placed inside of your +app/models+ directory and registered in your application's +config/application.rb+ file. For example, the +UserObserver+ above would be saved as +app/models/user_observer.rb+ and registered in +config/application.rb+ this way:
-# Activate observers that should always be running
+# Activate observers that should always be running.
config.active_record.observers = :user_observer
@@ -1217,7 +1230,7 @@ As usual, settings in +config/environments+ take precedence over those in +confi
h4. Sharing Observers
-By default, Rails will simply strip "Observer" from an observer's name to find the model it should observe. However, observers can also be used to add behavior to more than one model, and so it's possible to manually specify the models that our observer should observe.
+By default, Rails will simply strip "Observer" from an observer's name to find the model it should observe. However, observers can also be used to add behavior to more than one model, and thus it is possible to explicitly specify the models that our observer should observe:
class MailerObserver < ActiveRecord::Observer
@@ -1229,10 +1242,10 @@ class MailerObserver < ActiveRecord::Observer
end
-In this example, the +after_create+ method would be called whenever a +Registration+ or +User+ was created. Note that this new +MailerObserver+ would also need to be registered in +config/application.rb+ in order to take effect.
+In this example, the +after_create+ method will be called whenever a +Registration+ or +User+ is created. Note that this new +MailerObserver+ would also need to be registered in +config/application.rb+ in order to take effect:
-# Activate observers that should always be running
+# Activate observers that should always be running.
config.active_record.observers = :mailer_observer
@@ -1240,7 +1253,7 @@ h3. Transaction Callbacks
There are two additional callbacks that are triggered by the completion of a database transaction: +after_commit+ and +after_rollback+. These callbacks are very similar to the +after_save+ callback except that they don't execute until after database changes have either been committed or rolled back. They are most useful when your active record models need to interact with external systems which are not part of the database transaction.
-Consider, for example, the previous example where the +PictureFile+ model needs to delete a file after a record is destroyed. If anything raises an exception after the +after_destroy+ callback is called and the transaction rolls back, the file will have been deleted and the model will be left in an inconsistent state. For example, suppose that +picture_file_2+ in the code below is not valid and the +save!+ method raises an error.
+Consider, for example, the previous example where the +PictureFile+ model needs to delete a file after the corresponding record is destroyed. If anything raises an exception after the +after_destroy+ callback is called and the transaction rolls back, the file will have been deleted and the model will be left in an inconsistent state. For example, suppose that +picture_file_2+ in the code below is not valid and the +save!+ method raises an error.
PictureFile.transaction do
--
cgit v1.2.3
From 2c4e08d872869b116d2558256f8daeb0815a6dc0 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 5 Oct 2011 08:37:38 +1100
Subject: [engines guide] initial layout
---
railties/guides/source/engines.textile | 36 ++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 railties/guides/source/engines.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
new file mode 100644
index 0000000000..dc87ac4095
--- /dev/null
+++ b/railties/guides/source/engines.textile
@@ -0,0 +1,36 @@
+h2. Getting Started with Engines
+
+In this guide you will learn about engines and how they can be used to provide additional functionality to their host applications through a clean and very easy-to-use interface. You will learn the following things in this guide:
+
+* What are engines
+* Generating an engine
+* Building features for the engine
+* Hooking the engine into an application
+* Overriding engine functionality in the application
+
+endprologue.
+
+h3. What are engines?
+
+Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the `Rails::Application` class inheriting from `Rails::Engine`. Therefore, engines and applications share common functionality but are at the same time two separate beasts.
+
+h3. Generating an engine
+
+TODO: The engine that will be generated for this guide will be called "blorgh". It's a blogging engine that provides posts and comments and that's it.
+
+TODO: Describe here the process of generating an engine and what an engine comes with.
+
+h3. Providing engine functionality
+
+TODO: Brief explanation of what this engine is going to be doing and what we will have once we are done.
+TODO: Generate a posts scaffold (maybe?) for the engine
+TODO: Generate a comments scaffold (maybe?) for the engine
+
+h3. Hooking into application
+
+TODO: Application will provide a User foundation class which the engine hooks into through a configuration setting, configurable in the application's initializers. The engine will be mounted at the +/blog+ path in the application.
+
+h3. Overriding engine functionality
+
+TODO: Cover how to override engine functionality in the engine, such as controllers and views.
+IDEA: I like Devise's +devise :controllers => { "sessions" => "sessions" }+ idea. Perhaps we could incorporate that into the guide?
\ No newline at end of file
--
cgit v1.2.3
From a44bbfc1c7edb044ed9f73c7365a3a4a30b8b3fc Mon Sep 17 00:00:00 2001
From: Hendy Tanata
Date: Wed, 5 Oct 2011 17:35:58 +0800
Subject: Corrections to Active Record Validations and Callbacks guide.
---
railties/guides/source/active_record_validations_callbacks.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 6c6f29be32..600681ddd3 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -105,7 +105,7 @@ Person.create(:name => "John Doe").valid? # => true
Person.create(:name => nil).valid? # => false
-After Active Record performing validations, any errors found can be accessed through the +errors+ instance method, which returns a collection of errors. By definition an object is valid if this collection is empty after running validations.
+After Active Record has performed validations, any errors found can be accessed through the +errors+ instance method, which returns a collection of errors. By definition, an object is valid if this collection is empty after running validations.
Note that an object instantiated with +new+ will not report errors even if it's technically invalid, because validations are not run when using +new+.
@@ -812,7 +812,7 @@ Add this line in your Gemfile:
gem "dynamic_form"
-Now you will have access to the two help methods +error_messages+ and +error_messages_for+ in your view templates.
+Now you will have access to the two helper methods +error_messages+ and +error_messages_for+ in your view templates.
h4. +error_messages+ and +error_messages_for+
@@ -907,7 +907,7 @@ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
end
-The result look like the following:
+The result looks like the following:
!images/validation_error_messages.png(Validation error messages)!
--
cgit v1.2.3
From ea49935a6e0eca8783bc8d1bb46a6c518c073cac Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 5 Oct 2011 18:40:45 +0530
Subject: copy editing
---
.../guides/source/active_record_validations_callbacks.textile | 4 +---
railties/guides/source/getting_started.textile | 9 ++++-----
railties/guides/source/migrations.textile | 2 +-
3 files changed, 6 insertions(+), 9 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 600681ddd3..2a1e9bfc0c 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -1192,13 +1192,11 @@ h4. Creating Observers
For example, imagine a +User+ model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model's purpose, we should create an observer to contain the code implementing this functionality.
-Rails can create the initial code of the observers in a simple way. For instance, given a model +User+, the command
-
$ rails generate observer User
-generates file +app/models/user_observer.rb+ containing the observer class +UserObserver+:
+generates +app/models/user_observer.rb+ containing the observer class +UserObserver+:
class UserObserver < ActiveRecord::Observer
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 6812b6b9fe..bf6104b96b 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -705,7 +705,7 @@ $ rails console
TIP: The default console will make changes to your database. You can instead
open a console that will roll back any changes you make by using rails console
---sandbox .
+--sandbox.
After the console loads, you can use it to work with your application's models:
@@ -1074,7 +1074,7 @@ In the +update+ action, Rails first uses the +:id+ parameter passed back from
the edit view to locate the database record that's being edited. The
+update_attributes+ call then takes the +post+ parameter (a hash) from the request
and applies it to this record. If all goes well, the user is redirected to the
-post's +show+ action. If there are any problems, it's back to the +edit+ action to
+post's +show+ action. If there are any problems, it redirects back to the +edit+ action to
correct them.
h4. Destroying a Post
@@ -1115,8 +1115,7 @@ models and controllers. To create the new model, run this command in your
terminal:
-$ rails generate model Comment commenter:string body:text \
-> post:references
+$ rails generate model Comment commenter:string body:text post:references
This command will generate four files:
@@ -1520,7 +1519,7 @@ defined it as an instance variable.
h3. Deleting Comments
-Another important feature of a blog is being able to delete SPAM comments. To do
+Another important feature of a blog is being able to delete spam comments. To do
this, we need to implement a link of some sort in the view and a +DELETE+ action
in the +CommentsController+.
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index a73655d130..9c92d567d3 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -658,7 +658,7 @@ In many ways this is exactly what it is. This file is created by inspecting the
There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
-Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific the RDBMS of the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
+Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
h4. Schema Dumps and Source Control
--
cgit v1.2.3
From d6c7185d77158caee933e84b247e37bb6a67bf58 Mon Sep 17 00:00:00 2001
From: Prem Sichanugrist
Date: Wed, 5 Oct 2011 15:31:14 -0300
Subject: Update Rails routing guide to mention that `redirect()` is a 301
permanent redirect
I had to try out myself to realize that it's 301, so this should be helpful to everyone.
---
railties/guides/source/routing.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index 0a9f1e8388..bf18402b60 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -596,6 +596,8 @@ match "/stories/:name" => redirect {|params| "/posts/#{params[:name].pluralize}"
match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" }
+Please note that this redirection is a 301 "Moved Permanently" redirect. Keep in mind that some web browser or proxy server will cache this type of redirect, make the old page inaccessible.
+
In all of these cases, if you don't provide the leading host (+http://www.example.com+), Rails will take those details from the current request.
h4. Routing to Rack Applications
--
cgit v1.2.3
From 8d775d5f1d58e5c0d881383e8c6e869d1d360c8c Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Wed, 5 Oct 2011 22:14:41 +0100
Subject: Correction of code snippet tag from shell to ruby.
---
railties/guides/source/active_record_validations_callbacks.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 600681ddd3..9346a408e0 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -46,7 +46,7 @@ end
We can see how it works by looking at some +rails console+ output:
-
+
>> p = Person.new(:name => "John Doe")
=> #
>> p.new_record?
@@ -55,7 +55,7 @@ We can see how it works by looking at some +rails console+ output:
=> true
>> p.new_record?
=> false
-
+
Creating and saving a new record will send an SQL +INSERT+ operation to the database. Updating an existing record will send an SQL +UPDATE+ operation instead. Validations are typically run before these commands are sent to the database. If any validations fail, the object will be marked as invalid and Active Record will not perform the +INSERT+ or +UPDATE+ operation. This helps to avoid storing an invalid object in the database. You can choose to have specific validations run when an object is created, saved, or updated.
--
cgit v1.2.3
From cde529448bfb71a9acbbcc40622688f4511aecd5 Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Wed, 5 Oct 2011 22:52:50 +0100
Subject: Some small corrections and improvements to the text.
---
.../guides/source/active_record_querying.textile | 62 +++++++++++-----------
1 file changed, 32 insertions(+), 30 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index b1acdd189a..6b6f4d4983 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -13,7 +13,7 @@ endprologue.
WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in other versions of Rails.
-If you're used to using raw SQL to find database records then, generally, you will find that there are better ways to carry out the same operations in Rails. Active Record insulates you from the need to use SQL in most cases.
+If you're used to using raw SQL to find database records, then you will generally find that there are better ways to carry out the same operations in Rails. Active Record insulates you from the need to use SQL in most cases.
Code examples throughout this guide will refer to one or more of the following models:
@@ -69,16 +69,16 @@ The methods are:
All of the above methods return an instance of ActiveRecord::Relation.
-Primary operation of Model.find(options) can be summarized as:
+The primary operation of Model.find(options) can be summarized as:
* Convert the supplied options to an equivalent SQL query.
* Fire the SQL query and retrieve the corresponding results from the database.
* Instantiate the equivalent Ruby object of the appropriate model for every resulting row.
-* Run +after_find+ callbacks if any.
+* Run +after_find+ callbacks, if any.
h4. Retrieving a Single Object
-Active Record lets you retrieve a single object using five different ways.
+Active Record provides five different ways of retrieving a single object.
h5. Using a Primary Key
@@ -87,10 +87,10 @@ Using Model.find(primary_key), you can retrieve the object correspondin
# Find the client with primary key (id) 10.
client = Client.find(10)
-=> # "Ryan">
+=> #
-SQL equivalent of the above is:
+The SQL equivalent of the above is:
SELECT * FROM clients WHERE (clients.id = 10)
@@ -100,14 +100,14 @@ SELECT * FROM clients WHERE (clients.id = 10)
h5. +first+
-Model.first finds the first record matched by the supplied options. For example:
+Model.first finds the first record matched by the supplied options, if any. For example:
client = Client.first
=> #
-SQL equivalent of the above is:
+The SQL equivalent of the above is:
SELECT * FROM clients LIMIT 1
@@ -124,7 +124,7 @@ client = Client.last
=> #
-SQL equivalent of the above is:
+The SQL equivalent of the above is:
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
@@ -141,7 +141,7 @@ client = Client.first!
=> #
-SQL equivalent of the above is:
+The SQL equivalent of the above is:
SELECT * FROM clients LIMIT 1
@@ -158,7 +158,7 @@ client = Client.last!
=> #
-SQL equivalent of the above is:
+The SQL equivalent of the above is:
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
@@ -174,11 +174,11 @@ h5. Using Multiple Primary Keys
# Find the clients with primary keys 1 and 10.
-client = Client.find(1, 10) # Or even Client.find([1, 10])
-=> [# "Lifo">, # "Ryan">]
+client = Client.find([1, 10]) # Or even Client.find(1, 10)
+=> [#, #]
-SQL equivalent of the above is:
+The SQL equivalent of the above is:
SELECT * FROM clients WHERE (clients.id IN (1,10))
@@ -190,7 +190,7 @@ h4. Retrieving Multiple Objects in Batches
Sometimes you need to iterate over a large set of records. For example to send a newsletter to all users, to export some data, etc.
-The following may seem very straight forward at first:
+The following may seem very straightforward, at first:
# Very inefficient when users table has thousands of rows.
@@ -199,9 +199,9 @@ User.all.each do |user|
end
-But if the total number of rows in the table is very large, the above approach may vary from being under performant to just plain impossible.
+But if the total number of rows in the table is very large, the above approach may vary from being underperforming to being plain impossible.
-This is because +User.all.each+ makes Active Record fetch _the entire table_, build a model object per row, and keep the entire array in the memory. Sometimes that is just too many objects and demands too much memory.
+This is because +User.all.each+ makes Active Record fetch _the entire table_, build a model object per row, and keep the entire array of model objects in memory. Sometimes that is just too many objects and requires too much memory.
h5. +find_each+
@@ -215,9 +215,9 @@ end
*Configuring the batch size*
-Behind the scenes +find_each+ fetches rows in batches of +1000+ and yields them one by one. The size of the underlying batches is configurable via the +:batch_size+ option.
+Behind the scenes, +find_each+ fetches rows in batches of 1000 and yields them one by one. The size of the underlying batches is configurable via the +:batch_size+ option.
-To fetch +User+ records in batch size of +5000+:
+To fetch +User+ records in batches of 5000, we can use:
User.find_each(:batch_size => 5000) do |user|
@@ -227,9 +227,9 @@ end
*Starting batch find from a specific primary key*
-Records are fetched in ascending order on the primary key, which must be an integer. The +:start+ option allows you to configure the first ID of the sequence if the lowest is not the one you need. This may be useful for example to be able to resume an interrupted batch process if it saves the last processed ID as a checkpoint.
+Records are fetched in ascending order of the primary key, which must be an integer. The +:start+ option allows you to configure the first ID of the sequence whenever the lowest ID is not the one you need. This may be useful, for example, to be able to resume an interrupted batch process, provided it saves the last processed ID as a checkpoint.
-To send newsletters only to users with the primary key starting from +2000+:
+To send newsletters only to users with the primary key starting from 2000, we can use:
User.find_each(:batch_size => 5000, :start => 2000) do |user|
@@ -252,7 +252,9 @@ Invoice.find_in_batches(:include => :invoice_lines) do |invoices|
end
-The above will yield the supplied block with +1000+ invoices every time.
+The above will each time yield to the supplied block an arrays of 1000 invoices (or the remaining invoices, if less than 1000).
+
+NOTE: The +:include+ option allows you to name associations that should be loaded alongside with the models.
h3. Conditions
@@ -911,14 +913,14 @@ end
To call this +published+ scope we can call it on either the class:
-Post.published => [published posts]
+Post.published # => [published posts]
Or on an association consisting of +Post+ objects:
category = Category.first
-category.posts.published => [published posts belonging to this category]
+category.posts.published # => [published posts belonging to this category]
h4. Working with times
@@ -1030,7 +1032,7 @@ Suppose you want to find a client named 'Andy', and if there's none, create one
Client.where(:first_name => 'Andy').first_or_create(:locked => false)
-# =>
+=> #
The SQL generated by this method looks like this:
@@ -1068,7 +1070,7 @@ to your +Client+ model. If you try to create a new +Client+ without passing an +
Client.where(:first_name => 'Andy').first_or_create!(:locked => false)
-# => ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank
+=> ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank
h4. +first_or_initialize+
@@ -1077,13 +1079,13 @@ The +first_or_initialize+ method will work just like +first_or_create+ but it wi
nick = Client.where(:first_name => 'Nick').first_or_initialize(:locked => false)
-# =>
+=>
nick.persisted?
-# => false
+=> false
nick.new_record?
-# => true
+=> true
Because the object is not yet stored in the database, the SQL generated looks like this:
@@ -1096,7 +1098,7 @@ When you want to save it to the database, just call +save+:
nick.save
-# => true
+=> true
h3. Finding by SQL
--
cgit v1.2.3
From 1ba6b406981892f3501bc6a345573fd861641f9a Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 6 Oct 2011 08:40:36 +1100
Subject: [engines] Expanded 'What are engines?' and 'Generating an engine'
sections
---
railties/guides/source/engines.textile | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index dc87ac4095..83672fd66c 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -12,11 +12,30 @@ endprologue.
h3. What are engines?
-Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the `Rails::Application` class inheriting from `Rails::Engine`. Therefore, engines and applications share common functionality but are at the same time two separate beasts.
+Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the +Rails::Application+ class inheriting from +Rails::Engine+. Therefore, engines and applications share common functionality but are at the same time two separate beasts. Engines and applications also share a common structure, as you'll see later in this guide.
+
+Engines are also closely related to plugins where the two share a common +lib+ directory structure and are both generated using the +rails plugin new+ generator.
+
+The engine that will be generated for this guide will be called "blorgh". The engine will provide blogging functionality to its host applications, allowing for new posts and comments to be created. For now, you will be working solely within the engine itself and in later sections you'll see how to hook it into an application.
+
+Engines can also be isolated from their host applications. This means that an application is able to have a path provided by a routing helper such as +posts_path+ and use an engine also that provides a path also called +posts_path+, and the two would not clash. Along with this, controllers, models and table names are also namespaced. You'll see how to do this later in this guide.
+
+To see demonstrations of other engines, check out "Devise":https://github.com/plataformatec/devise, an engine that provides authentication for its parent applications, or "Forem":https://github.com/radar/forem, an engine that provides forum functionality.
h3. Generating an engine
-TODO: The engine that will be generated for this guide will be called "blorgh". It's a blogging engine that provides posts and comments and that's it.
+To generate an engine with Rails 3.1, you will need to run the plugin generator and pass it the +--mountable+ option. To generate the beginnings of the "blorgh" engine you will need to run this command in a terminal:
+
+
+$ rails plugin new blorgh --mountable
+
+
+The +--mountable+ option tells the plugin generator that you want to create an engine (which is a mountable plugin, hence the option name), creating the basic directory structure of an engine by providing things such as the foundations of an +app+ folder, as well a +config/routes.rb+ file. This generator also provides a file at +lib/blorgh/engine.rb+ which is identical in function to an application's +config/application.rb+ file.
+
+Inside the +app+ directory there lives the standard +assets+, +controllers+, +helpers+, +mailers+, +models+ and +views+ directories that you should be familiar with from an application.
+
+Within the +app/controllers+ directory there is a +blorgh+ directory and inside that a file called +application_controller.rb+. This file will provide any common functionality for the controllers of the engine. The +blorgh+ directory is where the other controllers for the engine will go. By placing them within this namespaced directory, you prevent them from possibly clashing with identically-named controllers within other engines or even within the application.
+
TODO: Describe here the process of generating an engine and what an engine comes with.
--
cgit v1.2.3
From 876d3f23d2370790623c6ef261d7c2366fb404d3 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 6 Oct 2011 08:47:06 +1100
Subject: [engines guide] More explanation for 'Generating an engine'
---
railties/guides/source/engines.textile | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 83672fd66c..ddd2e50a6c 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -34,10 +34,28 @@ The +--mountable+ option tells the plugin generator that you want to create an e
Inside the +app+ directory there lives the standard +assets+, +controllers+, +helpers+, +mailers+, +models+ and +views+ directories that you should be familiar with from an application.
-Within the +app/controllers+ directory there is a +blorgh+ directory and inside that a file called +application_controller.rb+. This file will provide any common functionality for the controllers of the engine. The +blorgh+ directory is where the other controllers for the engine will go. By placing them within this namespaced directory, you prevent them from possibly clashing with identically-named controllers within other engines or even within the application.
+At the root of the engine's directory, lives a +blorgh.gemspec+ file. When you include the engine into the application later on, you will do so with this line in a Rails application's +Gemfile+:
+
+
+ gem 'blorgh', :path => "vendor/engines/blorgh"
+
+
+By specifying it as a gem within the +Gemfile+, Bundler will load it as such, parsing this +blorgh.gemspec+ file and requiring a file within the +lib+ directory called +lib/blorgh.rb+. This file requires the +blorgh/engine.rb+ file (located at +lib/blorgh/engine.rb+) and defines a base module called +Blorgh+.
+
+
+require "blorgh/engine"
+module Blorgh
+end
+
-TODO: Describe here the process of generating an engine and what an engine comes with.
+Within +lib/blorgh/engine.rb+ is the base class for the engine:
+
+
+ TODO: lib/blorgh/engine.rb
+
+
+Within the +app/controllers+ directory there is a +blorgh+ directory and inside that a file called +application_controller.rb+. This file will provide any common functionality for the controllers of the engine. The +blorgh+ directory is where the other controllers for the engine will go. By placing them within this namespaced directory, you prevent them from possibly clashing with identically-named controllers within other engines or even within the application.
h3. Providing engine functionality
--
cgit v1.2.3
From 3d595c5eaeec43e5dc9f2930420506108b0ce813 Mon Sep 17 00:00:00 2001
From: Nick Quaranto
Date: Wed, 5 Oct 2011 22:27:33 -0400
Subject: use Rails.root.join for assets guide
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 7795b297f3..ccbc737f17 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -120,7 +120,7 @@ All subdirectories that exist within these three locations are added to the sear
You can add additional (fully qualified) paths to the pipeline in +config/application.rb+. For example:
-config.assets.paths << "#{Rails.root}/app/assets/flash"
+config.assets.paths << Rails.root.join("app", "assets", "flash")
h4. Coding Links to Assets
--
cgit v1.2.3
From 00751f02576719291822685bc97214af49887161 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 6 Oct 2011 13:32:21 +1100
Subject: [config guide] mention that to_prepare hooks are called upon every
request in dev, but only once in production
---
railties/guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index ce1d759d5b..e56932c26c 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -461,7 +461,7 @@ Rails has 5 initialization events which can be hooked into (listed in the order
* +before_initialize+: This is run directly before the initialization process of the application occurs with the +:bootstrap_hook+ initializer near the beginning of the Rails initialization process.
-* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built.
+* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built. More importantly, will run upon every request in +development+, but only once (during boot-up) in +production+ and +test+.
* +before_eager_load+: This is run directly before eager loading occurs, which is the default behaviour for the _production_ environment and not for the +development+ environment.
--
cgit v1.2.3
From 02eac2db9407ddebaca26ea6cb26d6d64a7fb24b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 6 Oct 2011 13:32:39 +1100
Subject: [config guide] Show example of defining initialization hooks
---
railties/guides/source/configuring.textile | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index e56932c26c..baf944cf8d 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -467,6 +467,25 @@ Rails has 5 initialization events which can be hooked into (listed in the order
* +after_initialize+: Run directly after the initialization of the application, but before the application initializers are run.
+To define an event for these hooks, use the block syntax within a +Rails::Aplication+, +Rails::Railtie+ or +Rails::Engine+ subclass:
+
+
+module YourApp
+ class Application < Rails::Application
+ config.before_initialize do
+ # initialization code goes here
+ end
+ end
+end
+
+
+Alternatively, you can also do it through the +config+ method on the +Rails.application+ object:
+
+
+Rails.application.config.before_initialize do
+ # initialization code goes here
+end
+
WARNING: Some parts of your application, notably observers and routing, are not yet set up at the point where the +after_initialize+ block is called.
--
cgit v1.2.3
From 79a719a6d27ad8f7782a8586392fc9716927c850 Mon Sep 17 00:00:00 2001
From: Hendy Tanata
Date: Thu, 6 Oct 2011 14:03:46 +0800
Subject: Grammar fixes for the routing guide.
---
railties/guides/source/routing.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index bf18402b60..f281009fee 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -596,7 +596,7 @@ match "/stories/:name" => redirect {|params| "/posts/#{params[:name].pluralize}"
match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" }
-Please note that this redirection is a 301 "Moved Permanently" redirect. Keep in mind that some web browser or proxy server will cache this type of redirect, make the old page inaccessible.
+Please note that this redirection is a 301 "Moved Permanently" redirect. Keep in mind that some web browsers or proxy servers will cache this type of redirect, making the old page inaccessible.
In all of these cases, if you don't provide the leading host (+http://www.example.com+), Rails will take those details from the current request.
--
cgit v1.2.3
From 9d091c038d5e3d35be09fbd0fd1603e3a4035ac2 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Thu, 6 Oct 2011 16:22:40 +0200
Subject: revises the precompilation section of the asset pipeline guide (web
server configuration for gzipped assets pending)
---
railties/guides/source/asset_pipeline.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 7795b297f3..7c79b202f1 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -398,7 +398,7 @@ This can be changed with the +config.assets.manifest+ option. A fully specified
config.assets.manifest = '/path/to/some/other/location'
-NOTE: If there are missing precompiled files in production you will get an AssetNoPrecompiledError exception indicating the name of the missing file(s).
+NOTE: If there are missing precompiled files in production you will get an Sprockets::Helpers::RailsHelper:: AssetPaths::AssetNotPrecompiledError exception indicating the name of the missing file(s).
h5. Server Configuration
@@ -436,9 +436,9 @@ location ~ ^/assets/ {
}
-When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disk. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used:
+When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. One the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
-For Apache:
+A possible configuration for Apache could be:
--
cgit v1.2.3
From 2224a06b72d77343acd2cb82ec27cb02c6ec6df6 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 6 Oct 2011 20:04:09 +0530
Subject: fix a space in the assets guide
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 7c79b202f1..1b06f4dedb 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -398,7 +398,7 @@ This can be changed with the +config.assets.manifest+ option. A fully specified
config.assets.manifest = '/path/to/some/other/location'
-NOTE: If there are missing precompiled files in production you will get an Sprockets::Helpers::RailsHelper:: AssetPaths::AssetNotPrecompiledError exception indicating the name of the missing file(s).
+NOTE: If there are missing precompiled files in production you will get an Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError exception indicating the name of the missing file(s).
h5. Server Configuration
--
cgit v1.2.3
From 545ddbdbc5b61716fb884488206567a130902f0a Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 6 Oct 2011 23:50:16 +0530
Subject: fix an example
---
railties/guides/source/caching_with_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 19378d63ce..4273d0dd64 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -188,7 +188,7 @@ end
You may notice that the actual product gets passed to the sweeper, so if we were caching the edit action for each product, we could add an expire method which specifies the page we want to expire:
- expire_action(:controller => 'products', :action => 'edit', :id => product)
+expire_action(:controller => 'products', :action => 'edit', :id => product.id)
Then we add it to our controller to tell it to call the sweeper when certain actions are called. So, if we wanted to expire the cached content for the list and edit actions when the create action was called, we could do the following:
--
cgit v1.2.3
From 29bf193cadae8c0b01f565caed75eb285ba8c958 Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira
Date: Thu, 6 Oct 2011 21:29:58 +0100
Subject: Undid previous change which violated the convention regarding output
(use "# =>") used in these guides. Corrected typo in previous correction.
(Thanks for pointing this out, vijaydev.)
---
.../guides/source/active_record_querying.textile | 26 +++++++++++-----------
1 file changed, 13 insertions(+), 13 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 6b6f4d4983..81d73c4ccc 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -87,7 +87,7 @@ Using Model.find(primary_key), you can retrieve the object correspondin
# Find the client with primary key (id) 10.
client = Client.find(10)
-=> #
+# => #
The SQL equivalent of the above is:
@@ -104,7 +104,7 @@ h5. +first+
client = Client.first
-=> #
+# => #
The SQL equivalent of the above is:
@@ -121,7 +121,7 @@ h5. +last+
client = Client.last
-=> #
+# => #
The SQL equivalent of the above is:
@@ -138,7 +138,7 @@ h5(#first_1). +first!+
client = Client.first!
-=> #
+# => #
The SQL equivalent of the above is:
@@ -155,7 +155,7 @@ h5(#last_1). +last!+
client = Client.last!
-=> #
+# => #
The SQL equivalent of the above is:
@@ -175,7 +175,7 @@ h5. Using Multiple Primary Keys
# Find the clients with primary keys 1 and 10.
client = Client.find([1, 10]) # Or even Client.find(1, 10)
-=> [#, #]
+# => [#, #]
The SQL equivalent of the above is:
@@ -252,7 +252,7 @@ Invoice.find_in_batches(:include => :invoice_lines) do |invoices|
end
-The above will each time yield to the supplied block an arrays of 1000 invoices (or the remaining invoices, if less than 1000).
+The above will each time yield to the supplied block an array of 1000 invoices (or the remaining invoices, if less than 1000).
NOTE: The +:include+ option allows you to name associations that should be loaded alongside with the models.
@@ -1032,7 +1032,7 @@ Suppose you want to find a client named 'Andy', and if there's none, create one
Client.where(:first_name => 'Andy').first_or_create(:locked => false)
-=> #
+# => #
The SQL generated by this method looks like this:
@@ -1070,7 +1070,7 @@ to your +Client+ model. If you try to create a new +Client+ without passing an +
Client.where(:first_name => 'Andy').first_or_create!(:locked => false)
-=> ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank
+# => ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank
h4. +first_or_initialize+
@@ -1079,13 +1079,13 @@ The +first_or_initialize+ method will work just like +first_or_create+ but it wi
nick = Client.where(:first_name => 'Nick').first_or_initialize(:locked => false)
-=>
+# =>
nick.persisted?
-=> false
+# => false
nick.new_record?
-=> true
+# => true
Because the object is not yet stored in the database, the SQL generated looks like this:
@@ -1098,7 +1098,7 @@ When you want to save it to the database, just call +save+:
nick.save
-=> true
+# => true
h3. Finding by SQL
--
cgit v1.2.3
From 0549ba10b30dc2b4d669f53359b67dd17c2ca6a6 Mon Sep 17 00:00:00 2001
From: clay shentrup
Date: Thu, 6 Oct 2011 16:09:36 -0700
Subject: Clarifying ambiguous description of require_self in the asset
pipeline
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index ccbc737f17..acf7495267 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -232,7 +232,7 @@ There's also a default +app/assets/stylesheets/application.css+ file which conta
The directives that work in the JavaScript files also work in stylesheets, obviously including stylesheets rather than JavaScript files. The +require_tree+ directive here works the same way as the JavaScript one, requiring all stylesheets from the current directory.
-In this example +require_self+ is used. This puts the CSS contained within the file (if any) at the top of any other CSS in this file unless +require_self+ is specified after another +require+ directive.
+In this example +require_self+ is used. This puts the CSS contained within the file (if any) at the precise location of the +require_self+ call. If +require_self+ is called more than once, only the last call is respected.
You can have as many manifest files as you need. For example the +admin.css+ and +admin.js+ manifest could contain the JS and CSS files that are used for the admin section of an application.
--
cgit v1.2.3
From ddee206dfb81c216ddc5c78544d305418010abaf Mon Sep 17 00:00:00 2001
From: Dimitar Dimitrov
Date: Fri, 7 Oct 2011 03:14:59 +0300
Subject: More understandable warning in the local_constant_names section
Rewrite the warning about local_constant_names in Ruby 1.8 to make it more understandable. Word ordering fixes in the same section.
---
railties/guides/source/active_support_core_extensions.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 5aee001545..addf5f78be 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -719,9 +719,9 @@ X.local_constants # => ["X2", "X1", "Y"], assumes Ruby 1.8
X::Y.local_constants # => ["X1", "Y1"], assumes Ruby 1.8
-The names are returned as strings in Ruby 1.8, and as symbols in Ruby 1.9. The method +local_constant_names+ returns always strings.
+The names are returned as strings in Ruby 1.8, and as symbols in Ruby 1.9. The method +local_constant_names+ always returns strings.
-WARNING: This method is exact if running under Ruby 1.9. In previous versions it may miss some constants if their value in some ancestor stores the exact same object than in the receiver.
+WARNING: This method returns precise results in Ruby 1.9. In older versions of Ruby, however, it may miss some constants in case the same constant exists in the receiver module as well as in any of its ancestors and both constants point to the same object (objects are compared using +Object#object_id+).
NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
--
cgit v1.2.3
From b1c20e37eccdfab7bb94d34f249c5e49256b9980 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Fri, 7 Oct 2011 15:05:14 +0200
Subject: asset pipeline guide: removes Apache config for serving
pre-compressed assets, and expands the information about nginx support for
this
A robust Apache configuration for this feature seems to be tricky,
one that takes into account Accept-Encoding, sets Vary, ensures
Content-Type is right, etc.
---
railties/guides/source/asset_pipeline.textile | 33 ++++++++++-----------------
1 file changed, 12 insertions(+), 21 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 1b06f4dedb..f2eade6bc6 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -438,36 +438,27 @@ location ~ ^/assets/ {
When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. One the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
-A possible configuration for Apache could be:
-
-
-
- # 2 lines to serve pre-gzipped version
- RewriteCond %{REQUEST_FILENAME}.gz -s
- RewriteRule ^(.+) $1.gz [L]
-
-
-# without these, Content-Type will be "application/x-gzip"
-
- ForceType text/css
-
-
-
- ForceType text/javascript
-
-
-
-For nginx:
+Nginx is able to do this automatically enabling +gzip_static+:
location ~ ^/(assets)/ {
root /path/to/public;
gzip_static on; # to serve pre-gzipped version
expires max;
- add_header Cache-Control public;
+ add_header Cache-Control public;
}
+This directive is available if the core module that provides this feature was compiled with the web server. Ubuntu packages, even +nginx-light+ have the module compiled. Otherwise, you may need to perform a manual compilation:
+
+
+./configure --with-http_gzip_static_module
+
+
+If you're compiling nginx with Phusion Passenger you'll need to pass that option when prompted.
+
+Unfortunately, a robust configuration for Apache is possible but tricky, please Google around.
+
h4. Live Compilation
In some circumstances you may wish to use live compilation. In this mode all requests for assets in the pipeline are handled by Sprockets directly.
--
cgit v1.2.3
From d4ea804e21695416a2473ef96ff73e06b74b24a0 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Fri, 7 Oct 2011 08:16:33 -0700
Subject: Replace the reference to the annotate_models plugin (unchanged since
2008) with more current annotate_models gem
---
railties/guides/source/migrations.textile | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 9c92d567d3..ec812f9e13 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -628,7 +628,11 @@ There is no need (and it is error prone) to deploy a new instance of an app by r
For example, this is how the test database is created: the current development database is dumped (either to +db/schema.rb+ or +db/development.sql+) and then loaded into the test database.
-Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations but is all summed up in the schema file. The "annotate_models":http://agilewebdevelopment.com/plugins/annotate_models plugin, which automatically adds (and updates) comments at the top of each model summarizing the schema, may also be of interest.
+Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is
+frequently spread across several migrations, but is summed up in the schema
+file. The "annotate_models":http://github.com/ctran/annotate_models
+gem automatically adds and updates comments at the top of each model summarizing
+the schema if you desire that functionality.
h4. Types of Schema Dumps
--
cgit v1.2.3
From fca2613ec444face807dc3aecf0d8b59acf30eae Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Fri, 7 Oct 2011 08:26:05 -0700
Subject: Correct formatting
---
railties/guides/source/migrations.textile | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index ec812f9e13..6ec4d7f70e 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -628,11 +628,7 @@ There is no need (and it is error prone) to deploy a new instance of an app by r
For example, this is how the test database is created: the current development database is dumped (either to +db/schema.rb+ or +db/development.sql+) and then loaded into the test database.
-Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is
-frequently spread across several migrations, but is summed up in the schema
-file. The "annotate_models":http://github.com/ctran/annotate_models
-gem automatically adds and updates comments at the top of each model summarizing
-the schema if you desire that functionality.
+Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations, but is summed up in the schema file. The "annotate_models":http://github.com/ctran/annotate_models gem automatically adds and updates comments at the top of each model summarizing the schema if you desire that functionality.
h4. Types of Schema Dumps
--
cgit v1.2.3
From cb244f4f70dbc22813e78e58f6a63392462417f7 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 7 Oct 2011 22:19:55 +0530
Subject: use https for github url
---
railties/guides/source/migrations.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 6ec4d7f70e..23e36b39f9 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -628,7 +628,7 @@ There is no need (and it is error prone) to deploy a new instance of an app by r
For example, this is how the test database is created: the current development database is dumped (either to +db/schema.rb+ or +db/development.sql+) and then loaded into the test database.
-Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations, but is summed up in the schema file. The "annotate_models":http://github.com/ctran/annotate_models gem automatically adds and updates comments at the top of each model summarizing the schema if you desire that functionality.
+Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations, but is summed up in the schema file. The "annotate_models":https://github.com/ctran/annotate_models gem automatically adds and updates comments at the top of each model summarizing the schema if you desire that functionality.
h4. Types of Schema Dumps
--
cgit v1.2.3
From d2db917841cacbdd6320460fd6fa3d07cd972139 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 8 Oct 2011 02:20:09 +0530
Subject: fix bad formatting in the assets guide
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index ef01cd32ac..df41c7a9e8 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -38,7 +38,7 @@ h4. Main Features
The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser must make to render a web page.
-While Rails already has a feature to concatenate these types of assets -- by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+ --, it has a series of limitations. For example, it cannot generate the caches in advance, and it is not able to transparently include assets provided by third-party libraries.
+While Rails already has a feature to concatenate these types of assets by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+, it has a series of limitations. For example, it cannot generate the caches in advance, and it is not able to transparently include assets provided by third-party libraries.
The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production, an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered.
--
cgit v1.2.3
From b2deeabffb542bb1683571db4f1a69a3426f838f Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sat, 8 Oct 2011 01:58:57 -0700
Subject: Correct stylesheet filename and remove reference to old stylesheet
compilation location
---
railties/guides/source/active_record_validations_callbacks.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 781b9001b6..2f78f1d0c8 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -880,7 +880,7 @@ The selectors used to customize the style of error messages are:
* +#error_explanation p+ - Style for the paragraph holding the message that appears right below the header of the +div+ element.
* +#error_explanation ul li+ - Style for the list items with individual error messages.
-If scaffolding was used, file +app/assets/stylesheets/scaffold.css.scss+ (which later compiles to +app/assets/stylesheets/scaffold.css+), will have been generated automatically. This file defines the red-based styles you saw in the examples above.
+If scaffolding was used, file +app/assets/stylesheets/scaffolds.css.scss+ will have been generated automatically. This file defines the red-based styles you saw in the examples above.
The name of the class and the id can be changed with the +:class+ and +:id+ options, accepted by both helpers.
--
cgit v1.2.3
From 62c03816e8b034ad0265548fe599667af6de5e87 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sat, 8 Oct 2011 03:59:13 -0700
Subject: copy editing
"updated the ajax_on_rails.textile for rails3"
---
railties/guides/source/active_record_validations_callbacks.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 2f78f1d0c8..665e7f9ccc 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -1162,7 +1162,7 @@ class PictureFile < ActiveRecord::Base
end
-Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we declared our callback as an instance method. This is particularly useful if the callbacks make use of the state of instantiated object. Often, however, it will make more sense to declare the callbacks as class methods:
+Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we declared our callback as an instance method. This is particularly useful if the callbacks make use of the state of the instantiated object. Often, however, it will make more sense to declare the callbacks as class methods:
class PictureFileCallbacks
--
cgit v1.2.3
From 6a5eeab3cde28f0faf187b681fde4e52a96a1268 Mon Sep 17 00:00:00 2001
From: "Karunakar (Ruby)"
Date: Sun, 9 Oct 2011 00:03:12 +0530
Subject: Revert "Revert "updated the ajax_on_rails.textile for rails3" because
of invalid git user"
This reverts commit 5d2ffbb992b4ab875a121761fc0cf14dcaa12033.
---
railties/guides/source/ajax_on_rails.textile | 69 ++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile
index 29d4fae888..b5d4fb10f8 100644
--- a/railties/guides/source/ajax_on_rails.textile
+++ b/railties/guides/source/ajax_on_rails.textile
@@ -3,7 +3,7 @@ h2. AJAX on Rails
This guide covers the built-in Ajax/JavaScript functionality of Rails (and more); it will enable you to create rich and dynamic AJAX applications with ease! We will cover the following topics:
* Quick introduction to AJAX and related technologies
-* Handling JavaScript the Rails way: Rails helpers, Prototype and script.aculo.us
+* Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS)
* Testing JavaScript functionality
endprologue.
@@ -26,13 +26,74 @@ How do 'standard' and AJAX requests differ, why does this matter for understandi
h3. Built-in Rails Helpers
-Rails' JavaScript framework of choice is "Prototype":http://www.prototypejs.org. Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views.
+Rails 3.1 default javaScript framework of choice is Jquery "http://jquery.com".
+
+jQuery is a new kind of JavaScript Library and jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
+
+jquery-rails is default gem and it adds Ruby on Rails style restful HTTP verbs to the jQuery library. Instead of sending an actual PUT or DELETE request (many browsers only support GET and POST), jQuery will make a POST request with an additional data parameter called _method set to the proper verb. Ruby on Rails can then act accordingly.
+
+Jquery helpers you can access defaultly - typically in your master layout, application.html.erb - like so:
+
+
+javascript_include_tag :defaults
+
+
+jquery-rails is default in Gemfile.
+
+
+javascript_include_tag :defaults
+
+
+All the remote_ true option to the original non-remote method
+
+==== Examples
+
+ button_to "New", :action => "new", :form_class => "new-thing"
+
+# => ""
-To get access to these helpers, all you have to do is to include the prototype framework in your pages - typically in your master layout, application.html.erb - like so:
-javascript_include_tag 'prototype'
+ button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" }
+# => ""
+
+
+
+
+button_to "Delete Image", { :action => "delete", :id => @image.id },
+ :confirm => "Are you sure?", :method => :delete
+
+
+# => ""
+
+
+ button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
+ :method => "delete", :remote => true, :disable_with => 'loading...')
+
+# => ""
+
+TODO: Write more Jquery helpers here.
+
+You can also specify the prototype to use instead of jquery or any other libraries
+
+rails new app_name -j prototype
+
+Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views.
You are ready to add some AJAX love to your Rails app!
--
cgit v1.2.3
From 3deb35ea5c92d576b3979e39f816e83d76355836 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sat, 8 Oct 2011 22:45:31 -0700
Subject: copy editing
---
railties/guides/source/association_basics.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index f5f0f9340c..5e8610073b 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -566,7 +566,7 @@ The build_association method returns a new object of the assoc
h6(#belongs_to-create_association). create_association(attributes = {})
-The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations).
+The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
@customer = @order.create_customer(:customer_number => 123,
--
cgit v1.2.3
From ac8555b5a0f52d02b66d2074672d287db0bb91dc Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sat, 8 Oct 2011 23:02:33 -0700
Subject: copy editing
---
railties/guides/source/association_basics.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 5e8610073b..06cb199fd9 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -211,7 +211,7 @@ end
h4. Choosing Between +belongs_to+ and +has_one+
-If you want to set up a 1–1 relationship between two models, you'll need to add +belongs_to+ to one, and +has_one+ to the other. How do you know which is which?
+If you want to set up a one-to-one relationship between two models, you'll need to add +belongs_to+ to one, and +has_one+ to the other. How do you know which is which?
The distinction is in where you place the foreign key (it goes on the table for the class declaring the +belongs_to+ association), but you should give some thought to the actual meaning of the data as well. The +has_one+ relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier. This suggests that the correct relationships are like this:
@@ -576,7 +576,7 @@ The create_association method returns a new object of the asso
h5. Options for +belongs_to+
-In many situations, you can use the default behavior of +belongs_to+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +belongs_to+ association. For example, an association with several options might look like this:
+In many situations, you can use the default behavior of +belongs_to+ without any customization. But despite Rails' emphasis of convention over configuration, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +belongs_to+ association. For example, an association with several options might look like this:
class Order < ActiveRecord::Base
@@ -842,7 +842,7 @@ The create_association method returns a new object of the asso
h5. Options for +has_one+
-In many situations, you can use the default behavior of +has_one+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_one+ association. For example, an association with several options might look like this:
+In many situations, you can use the default behavior of +has_one+ without any customization. But despite Rails' emphasis of convention over configuration, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_one+ association. For example, an association with several options might look like this:
class Supplier < ActiveRecord::Base
--
cgit v1.2.3
From 43baad78f758fe16485202643721a07852b25376 Mon Sep 17 00:00:00 2001
From: "Karunakar (Ruby)"
Date: Sun, 9 Oct 2011 12:46:25 +0530
Subject: improving the docs for ajax_on_rails
---
railties/guides/source/ajax_on_rails.textile | 35 +++++++++++++++++-----------
1 file changed, 22 insertions(+), 13 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile
index b5d4fb10f8..9f5afc87de 100644
--- a/railties/guides/source/ajax_on_rails.textile
+++ b/railties/guides/source/ajax_on_rails.textile
@@ -44,23 +44,30 @@ jquery-rails is default in Gemfile.
javascript_include_tag :defaults
+h4. Examples
+
All the remote_ true option to the original non-remote method
-==== Examples
button_to "New", :action => "new", :form_class => "new-thing"
-# => ""
+
+will produce
+
+
button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" }
-# => ""
+
+will produce
+
+
@@ -69,12 +76,14 @@ button_to "Delete Image", { :action => "delete", :id => @image.id },
:confirm => "Are you sure?", :method => :delete
-# => ""
+will produce
+
+
button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
--
cgit v1.2.3
From 9de9f6b4d0422e23e1eec9c59bbda880684e45c9 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sun, 9 Oct 2011 01:50:53 -0700
Subject: Copy editing to improve readability and remove any potential
ambiguity
---
railties/guides/source/association_basics.textile | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 06cb199fd9..8943bfa0a3 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -566,7 +566,7 @@ The build_association method returns a new object of the assoc
h6(#belongs_to-create_association). create_association(attributes = {})
-The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
+The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through this object's foreign key will be set, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
@customer = @order.create_customer(:customer_number => 123,
@@ -760,9 +760,9 @@ h6(#belongs_to-validate). +: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.
-h5(#belongs_to-how_to_know_whether_theres_an_associated_object). How To Know Whether There's an Associated Object?
+h5(#belongs_to-do_any_associated_objects_exist). Do Any Associated Objects Exist?
-To know whether there's and associated object just check association.nil?:
+You can see if any associated objects exist by using the association.nil? method:
if @order.customer.nil?
@@ -834,7 +834,7 @@ The build_association method returns a new object of the assoc
h6(#has_one-create_association). create_association(attributes = {})
-The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations).
+The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be set, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
@account = @supplier.create_account(:terms => "Net 30")
@@ -980,9 +980,9 @@ h6(#has_one-validate). +: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.
-h5(#has_one-how_to_know_whether_theres_an_associated_object). How To Know Whether There's an Associated Object?
+h5(#has_one-do_any_associated_objects_exist). Do Any Associated Objects Exist?
-To know whether there's and associated object just check association.nil?:
+You can see if any associated objects exist by using the association.nil? method:
if @supplier.account.nil?
@@ -1147,7 +1147,7 @@ The collection.build method returns one or more new objects of
h6(#has_many-collection-create). collection.create(attributes = {})
-The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object _will_ be saved (assuming that it passes any validations).
+The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
@order = @customer.orders.create(:order_date => Time.now,
@@ -1576,7 +1576,7 @@ The collection.build method returns a new object of the associ
h6(#has_and_belongs_to_many-create-attributes). collection.create(attributes = {})
-The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through the join table will be created, and the associated object _will_ be saved (assuming that it passes any validations).
+The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through the join table will be created, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
@assembly = @part.assemblies.create(
--
cgit v1.2.3
From da773a24beab90236802a2ca39e5b124b1b5d456 Mon Sep 17 00:00:00 2001
From: Roy Tomeij
Date: Sun, 9 Oct 2011 13:38:47 +0200
Subject: Add note about how Sass & Sprockets don't match
---
railties/guides/source/asset_pipeline.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index ef01cd32ac..303066b752 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -19,7 +19,7 @@ Prior to Rails 3.1 these features were added through third-party Ruby libraries
By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "fast by default" strategy as outlined by DHH in his keynote at RailsConf 2011.
-In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by putting this line inside the application class definition:
+In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by publicing this line inside the application class definition:
config.assets.enabled = false
@@ -234,6 +234,8 @@ The directives that work in the JavaScript files also work in stylesheets, obvio
In this example +require_self+ is used. This puts the CSS contained within the file (if any) at the precise location of the +require_self+ call. If +require_self+ is called more than once, only the last call is respected.
+NOTE. If you want to use multiple Sass files, use the "Sass +@import+ rule":http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#import instead of the Sprockets directives. Using Sprockets directives all Sass files exist within their own scope, making variables or mixins only available within the document they were defined in.
+
You can have as many manifest files as you need. For example the +admin.css+ and +admin.js+ manifest could contain the JS and CSS files that are used for the admin section of an application.
The same remarks about ordering made above apply. In particular, you can specify individual files and they are compiled in the order specified:
--
cgit v1.2.3
From d214e54e7aadd15bbf872c3deae24908258e8cb8 Mon Sep 17 00:00:00 2001
From: Roy Tomeij
Date: Sun, 9 Oct 2011 13:45:54 +0200
Subject: Fix a typo that was mysteriously entered in previous commit
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 303066b752..1b245b1fc7 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -19,7 +19,7 @@ Prior to Rails 3.1 these features were added through third-party Ruby libraries
By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "fast by default" strategy as outlined by DHH in his keynote at RailsConf 2011.
-In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by publicing this line inside the application class definition:
+In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +config/application.rb+ by putting this line inside the application class definition:
config.assets.enabled = false
--
cgit v1.2.3
From 3a72c01be2add83c76e6180d60a520491484c01e Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 9 Oct 2011 19:58:14 +0530
Subject: Corrections to the ajax guide recent changes. This guide is very
outdated and will need a lot of changes to make it useful for Rails 3+
---
railties/guides/source/ajax_on_rails.textile | 58 +++++++++++++---------------
1 file changed, 26 insertions(+), 32 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile
index 9f5afc87de..3a0ccfe9b2 100644
--- a/railties/guides/source/ajax_on_rails.textile
+++ b/railties/guides/source/ajax_on_rails.textile
@@ -3,7 +3,7 @@ h2. AJAX on Rails
This guide covers the built-in Ajax/JavaScript functionality of Rails (and more); it will enable you to create rich and dynamic AJAX applications with ease! We will cover the following topics:
* Quick introduction to AJAX and related technologies
-* Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS)
+* Unobtrusive JavaScript helpers with drivers for Prototype, jQuery etc
* Testing JavaScript functionality
endprologue.
@@ -26,19 +26,7 @@ How do 'standard' and AJAX requests differ, why does this matter for understandi
h3. Built-in Rails Helpers
-Rails 3.1 default javaScript framework of choice is Jquery "http://jquery.com".
-
-jQuery is a new kind of JavaScript Library and jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
-
-jquery-rails is default gem and it adds Ruby on Rails style restful HTTP verbs to the jQuery library. Instead of sending an actual PUT or DELETE request (many browsers only support GET and POST), jQuery will make a POST request with an additional data parameter called _method set to the proper verb. Ruby on Rails can then act accordingly.
-
-Jquery helpers you can access defaultly - typically in your master layout, application.html.erb - like so:
-
-
-javascript_include_tag :defaults
-
-
-jquery-rails is default in Gemfile.
+Rails 3.1 ships with "jQuery":http://jquery.com as the default JavaScript library. The Gemfile contains gem 'jquery-rails' which makes the jQuery files available to the application automatically. This can be accessed as:
javascript_include_tag :defaults
@@ -46,63 +34,69 @@ javascript_include_tag :defaults
h4. Examples
-All the remote_ true option to the original non-remote method
+All the remote_method helpers has been removed. To make them working with AJAX, simply pass the :remote => true option to the original non-remote method.
- button_to "New", :action => "new", :form_class => "new-thing"
+button_to "New", :action => "new", :form_class => "new-thing"
will produce
+
-
+
- button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" }
+button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" }
will produce
+
-
+
-
button_to "Delete Image", { :action => "delete", :id => @image.id },
:confirm => "Are you sure?", :method => :delete
will produce
+
+
-
- button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
+
+button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
:method => "delete", :remote => true, :disable_with => 'loading...')
-# => ""
-TODO: Write more Jquery helpers here.
+will produce
-You can also specify the prototype to use instead of jquery or any other libraries
+
+
+
-rails new app_name -j prototype
+You can also choose to use Prototype instead of jQuery and specify the option using +-j+ switch while generating the application.
-Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views.
+
+rails new app_name -j prototype
+
You are ready to add some AJAX love to your Rails app!
--
cgit v1.2.3
From b9b4cfcebc3f77e2cf828450ccb9ac1b2f867a67 Mon Sep 17 00:00:00 2001
From: Dan McDonald
Date: Sun, 9 Oct 2011 09:31:11 -0600
Subject: ActiveRecordStore is now called SessionStore.
---
railties/guides/source/security.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index 73c7a80ff6..0f100e0adf 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -82,9 +82,9 @@ This will also be a good idea, if you modify the structure of an object and old
h4. Session Storage
--- _Rails provides several storage mechanisms for the session hashes. The most important are ActiveRecordStore and CookieStore._
+-- _Rails provides several storage mechanisms for the session hashes. The most important are SessionStore and CookieStore._
-There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose ActiveRecordStore (or one of its derivatives) over file storage due to performance and maintenance reasons. ActiveRecordStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.
+There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose SessionStore (or one of its derivatives) over file storage due to performance and maintenance reasons. SessionStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.
Rails 2 introduced a new default session storage, CookieStore. CookieStore saves the session hash directly in a cookie on the client-side. The server retrieves the session hash from the cookie and eliminates the need for a session id. That will greatly increase the speed of the application, but it is a controversial storage option and you have to think about the security implications of it:
--
cgit v1.2.3
From 74b9441c0df39bba58b453701b2f3add72fc7ebe Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sun, 9 Oct 2011 09:36:19 -0700
Subject: Copy editing: s/Rails guesses/Rails assumes/g
---
railties/guides/source/association_basics.textile | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 8943bfa0a3..5f8997e7be 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -671,7 +671,7 @@ WARNING: You should not specify this option on a +belongs_to+ association that i
h6(#belongs_to-foreign_key). +:foreign_key+
-By convention, Rails guesses that the column used to hold the foreign key on this model is the name of the association with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
+By convention, Rails assumes that the column used to hold the foreign key on this model is the name of the association with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
class Order < ActiveRecord::Base
@@ -902,7 +902,7 @@ If you set the +:dependent+ option to +:destroy+, then deleting this object will
h6(#has_one-foreign_key). +:foreign_key+
-By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
+By convention, Rails assumes that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
class Supplier < ActiveRecord::Base
@@ -954,7 +954,7 @@ The +:order+ option dictates the order in which associated objects will be recei
h6(#has_one-primary_key). +:primary_key+
-By convention, Rails guesses that the column used to hold the primary key of this model is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option.
+By convention, Rails assumes that the column used to hold the primary key of this model is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option.
h6(#has_one-readonly). +:readonly+
@@ -1262,7 +1262,7 @@ Normally Rails automatically generates the proper SQL to fetch the association m
h6(#has_many-foreign_key). +:foreign_key+
-By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
+By convention, Rails assumes that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
class Customer < ActiveRecord::Base
@@ -1345,7 +1345,7 @@ end
h6(#has_many-primary_key). +:primary_key+
-By convention, Rails guesses that the column used to hold the primary key of the association is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option.
+By convention, Rails assumes that the column used to hold the primary key of the association is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option.
h6(#has_many-readonly). +:readonly+
@@ -1619,7 +1619,7 @@ The +has_and_belongs_to_many+ association supports these options:
h6(#has_and_belongs_to_many-association_foreign_key). +:association_foreign_key+
-By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix +_id+ added. The +:association_foreign_key+ option lets you set the name of the foreign key directly:
+By convention, Rails assumes that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix +_id+ added. The +:association_foreign_key+ option lets you set the name of the foreign key directly:
TIP: The +:foreign_key+ and +:association_foreign_key+ options are useful when setting up a many-to-many self-join. For example:
@@ -1687,7 +1687,7 @@ Normally Rails automatically generates the proper SQL to fetch the association m
h6(#has_and_belongs_to_many-foreign_key). +:foreign_key+
-By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
+By convention, Rails assumes that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly:
class User < ActiveRecord::Base
--
cgit v1.2.3
From 5f632a88a63142a2cd4e734b0ab7486bf34d64bf Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sun, 9 Oct 2011 15:56:01 -0700
Subject: Minor copy editing
---
railties/guides/source/association_basics.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 5f8997e7be..56f51e6ae7 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -1551,7 +1551,7 @@ The collection.find method finds objects within the collection
:conditions => ["created_at > ?", 2.days.ago])
-NOTE: Starting Rails 3, supplying options to +ActiveRecord::Base.find+ method is discouraged. Use collection.where instead when you need to pass conditions.
+NOTE: Beginning with Rails 3, supplying options to the +ActiveRecord::Base.find+ method is discouraged. Use collection.where instead when you need to pass conditions.
h6(#has_and_belongs_to_many-collection-where). collection.where(...)
--
cgit v1.2.3
From 11b183eb927d8cd12ce33e43d9f4e2642fb988e7 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sun, 9 Oct 2011 16:07:30 -0700
Subject: Copy editing to improve readability, consistency, and tone
---
railties/guides/source/association_basics.textile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 56f51e6ae7..479a3c1e30 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -576,7 +576,7 @@ The create_association method returns a new object of the asso
h5. Options for +belongs_to+
-In many situations, you can use the default behavior of +belongs_to+ without any customization. But despite Rails' emphasis of convention over configuration, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +belongs_to+ association. For example, an association with several options might look like this:
+While Rails uses intelligent defaults that will work well in most situations, there may be times when you want to customize the behavior of the +belongs_to+ association reference. Such customizations can easily be accomplished by passing options when you create the association. For example, this assocation uses two such options:
class Order < ActiveRecord::Base
@@ -842,7 +842,7 @@ The create_association method returns a new object of the asso
h5. Options for +has_one+
-In many situations, you can use the default behavior of +has_one+ without any customization. But despite Rails' emphasis of convention over configuration, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_one+ association. For example, an association with several options might look like this:
+While Rails uses intelligent defaults that will work well in most situations, there may be times when you want to customize the behavior of the +has_one+ association reference. Such customizations can easily be accomplished by passing options when you create the association. For example, this assocation uses two such options:
class Supplier < ActiveRecord::Base
@@ -1156,7 +1156,7 @@ The collection.create method returns a new object of the assoc
h5. Options for +has_many+
-In many situations, you can use the default behavior for +has_many+ without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_many+ association. For example, an association with several options might look like this:
+While Rails uses intelligent defaults that will work well in most situations, there may be times when you want to customize the behavior of the +has_many+ association reference. Such customizations can easily be accomplished by passing options when you create the association. For example, this assocation uses two such options:
class Customer < ActiveRecord::Base
@@ -1585,7 +1585,7 @@ The collection.create method returns a new object of the assoc
h5. Options for +has_and_belongs_to_many+
-In many situations, you can use the default behavior for +has_and_belongs_to_many+ without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_and_belongs_to_many+ association. For example, an association with several options might look like this:
+While Rails uses intelligent defaults that will work well in most situations, there may be times when you want to customize the behavior of the +has_and_belongs_to_many+ association reference. Such customizations can easily be accomplished by passing options when you create the association. For example, this assocation uses two such options:
class Parts < ActiveRecord::Base
--
cgit v1.2.3
From 454492dfd7d364bb4386935bd8d5f636d5163e2b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 6 Oct 2011 18:20:38 +1100
Subject: [engines guide] Credit where credit is due
---
railties/guides/source/engines.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index ddd2e50a6c..ce041141a0 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -22,6 +22,8 @@ Engines can also be isolated from their host applications. This means that an ap
To see demonstrations of other engines, check out "Devise":https://github.com/plataformatec/devise, an engine that provides authentication for its parent applications, or "Forem":https://github.com/radar/forem, an engine that provides forum functionality.
+Finally, engines would not have be possible without the work of James Adam, Piotr Sarnacki, the Rails Core Team, and a number of other people. If you ever meet them, don't forget to say thanks!
+
h3. Generating an engine
To generate an engine with Rails 3.1, you will need to run the plugin generator and pass it the +--mountable+ option. To generate the beginnings of the "blorgh" engine you will need to run this command in a terminal:
--
cgit v1.2.3
From c580812a5560f002eeefa6ddba8c4e8acc0adf54 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 6 Oct 2011 18:28:50 +1100
Subject: [engines guide] Credit where credit is due + explaning directory
structure
---
railties/guides/source/engines.textile | 43 +++++++++++++++++++++++++++++++---
1 file changed, 40 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index ce041141a0..6b0c8b3b2f 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -12,7 +12,7 @@ endprologue.
h3. What are engines?
-Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the +Rails::Application+ class inheriting from +Rails::Engine+. Therefore, engines and applications share common functionality but are at the same time two separate beasts. Engines and applications also share a common structure, as you'll see later in this guide.
+Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the +Rails::Application+ class inheriting from +Rails::Engine+. Therefore, engines and applications share common functionality but are at the same time two separate beasts. Engines and applications also share a common structure, as you'll see througout this guide.
Engines are also closely related to plugins where the two share a common +lib+ directory structure and are both generated using the +rails plugin new+ generator.
@@ -34,7 +34,9 @@ $ rails plugin new blorgh --mountable
The +--mountable+ option tells the plugin generator that you want to create an engine (which is a mountable plugin, hence the option name), creating the basic directory structure of an engine by providing things such as the foundations of an +app+ folder, as well a +config/routes.rb+ file. This generator also provides a file at +lib/blorgh/engine.rb+ which is identical in function to an application's +config/application.rb+ file.
-Inside the +app+ directory there lives the standard +assets+, +controllers+, +helpers+, +mailers+, +models+ and +views+ directories that you should be familiar with from an application.
+h4. Inside an engine
+
+h5. Critical files
At the root of the engine's directory, lives a +blorgh.gemspec+ file. When you include the engine into the application later on, you will do so with this line in a Rails application's +Gemfile+:
@@ -54,11 +56,46 @@ end
Within +lib/blorgh/engine.rb+ is the base class for the engine:
- TODO: lib/blorgh/engine.rb
+module Blorgh
+ class Engine < Rails::Engine
+ isolate_namespace Blorgh
+ end
+end
+By inheriting from the +Rails::Engine+ class, this engine gains all the functionality it needs, such as being able to serve requests to its controllers.
+
+The +isolate_namespace+ method here deserves special notice. This call is responsible for isolating the controllers, models, routes and other things into their own namespace. Without this, there is a possibility that the engine's components could "leak" into the application, causing unwanted disruption. It is recommended that this line be left within this file.
+
+h5. +app+ directory
+
+Inside the +app+ directory there lives the standard +assets+, +controllers+, +helpers+, +mailers+, +models+ and +views+ directories that you should be familiar with from an application. The +helpers+, +mailers+ and +models+ directories are empty and so aren't described in this section. We'll look more into models in a future section.
+
+Within the +app/assets+ directory, there is the +images+, +javascripts+ and +stylesheets+ directories which, again, you should be familiar with due to their similarities of an application. One difference here however is that each directory contains a sub-directory with the engine name. Because this engine is going to be namespaced, its assets should be too.
+
Within the +app/controllers+ directory there is a +blorgh+ directory and inside that a file called +application_controller.rb+. This file will provide any common functionality for the controllers of the engine. The +blorgh+ directory is where the other controllers for the engine will go. By placing them within this namespaced directory, you prevent them from possibly clashing with identically-named controllers within other engines or even within the application.
+Lastly, the +app/views+ directory contains a +layouts+ folder which contains file at +blorgh/application.html.erb+ which allows you to specify a layout for the engine. If this engine is to be used as a stand-alone engine, then we would add any customization to its layout in this file, rather than the applications +app/views/layouts/application.html.erb+ file.
+
+h5. +script+ directory
+
+This directory contains one file, +script/rails+, which allows you to use the +rails+ sub-commands and generators just like you would within an application. This means that you will very easily be able to generate new controllers and models for this engine.
+
+h5. +test+ directory
+
+The +test+ directory is where tests for the engine will go. To test the engine, there is a cut-down version of a Rails application embedded within it at +test/dummy+. This application will mount the engine in the +test/dummy/config/routes.rb+ file:
+
+
+Rails.application.routes.draw do
+
+ mount Blorgh::Engine => "/blorgh"
+end
+
+
+This line mounts the engine at the path of +/blorgh+, which will make it accessible through the application only at that path. We will look more into mounting an engine after we have developed some features.
+
+Also in the test directory is the +test/integration+ directory, where integration tests for the engine should be placed.
+
h3. Providing engine functionality
TODO: Brief explanation of what this engine is going to be doing and what we will have once we are done.
--
cgit v1.2.3
From 685c24d730edb3e3c5f3b750e510863c1d9aff95 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 7 Oct 2011 07:15:14 +1100
Subject: [engines guide] reword first two dot points in prologue
---
railties/guides/source/engines.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 6b0c8b3b2f..17c48319ac 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -2,8 +2,8 @@ h2. Getting Started with Engines
In this guide you will learn about engines and how they can be used to provide additional functionality to their host applications through a clean and very easy-to-use interface. You will learn the following things in this guide:
-* What are engines
-* Generating an engine
+* What makes an engine
+* How to generate an engine
* Building features for the engine
* Hooking the engine into an application
* Overriding engine functionality in the application
--
cgit v1.2.3
From b02bd74c13ba09217bb45b5fa228ddd9592a2600 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 7 Oct 2011 09:06:43 +1100
Subject: [engines guide] begin explaining what the scaffold generator outputs
within an engine
---
railties/guides/source/engines.textile | 58 ++++++++++++++++++++++++++++++++--
1 file changed, 56 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 17c48319ac..7b1c0a59e2 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -75,7 +75,7 @@ Within the +app/assets+ directory, there is the +images+, +javascripts+ and +sty
Within the +app/controllers+ directory there is a +blorgh+ directory and inside that a file called +application_controller.rb+. This file will provide any common functionality for the controllers of the engine. The +blorgh+ directory is where the other controllers for the engine will go. By placing them within this namespaced directory, you prevent them from possibly clashing with identically-named controllers within other engines or even within the application.
-Lastly, the +app/views+ directory contains a +layouts+ folder which contains file at +blorgh/application.html.erb+ which allows you to specify a layout for the engine. If this engine is to be used as a stand-alone engine, then we would add any customization to its layout in this file, rather than the applications +app/views/layouts/application.html.erb+ file.
+Lastly, the +app/views+ directory contains a +layouts+ folder which contains file at +blorgh/application.html.erb+ which allows you to specify a layout for the engine. If this engine is to be used as a stand-alone engine, then you would add any customization to its layout in this file, rather than the applications +app/views/layouts/application.html.erb+ file.
h5. +script+ directory
@@ -92,12 +92,66 @@ Rails.application.routes.draw do
end
-This line mounts the engine at the path of +/blorgh+, which will make it accessible through the application only at that path. We will look more into mounting an engine after we have developed some features.
+This line mounts the engine at the path of +/blorgh+, which will make it accessible through the application only at that path. We will look more into mounting an engine after some features have been developed.
Also in the test directory is the +test/integration+ directory, where integration tests for the engine should be placed.
h3. Providing engine functionality
+The engine that this guide covers will provide posting and commenting functionality.
+
+h4. Generating a post resource
+
+The first thing to generate for a blog engine is the +Post+ model and related controller. To quickly generate this, you can use the Rails scaffold generator.
+
+
+$ rails generate scaffold post title:string text:text
+invoke active_record
+create db/migrate/20111006201642_create_blorgh_posts.rb
+create app/models/blorgh/post.rb
+invoke test_unit
+create test/unit/blorgh/post_test.rb
+create test/fixtures/blorgh/posts.yml
+ route resources :posts
+invoke scaffold_controller
+create app/controllers/blorgh/posts_controller.rb
+invoke erb
+create app/views/blorgh/posts
+create app/views/blorgh/posts/index.html.erb
+create app/views/blorgh/posts/edit.html.erb
+create app/views/blorgh/posts/show.html.erb
+create app/views/blorgh/posts/new.html.erb
+create app/views/blorgh/posts/_form.html.erb
+invoke test_unit
+create test/functional/blorgh/posts_controller_test.rb
+invoke helper
+create app/helpers/blorgh/posts_helper.rb
+invoke test_unit
+create test/unit/helpers/blorgh/posts_helper_test.rb
+invoke assets
+invoke js
+create app/assets/javascripts/blorgh/posts.js
+invoke css
+create app/assets/stylesheets/blorgh/posts.css
+invoke css
+create app/assets/stylesheets/scaffold.css
+
+
+The first thing that the scaffold generator does is invoke the +active_record+ generator, which generates a migration and a model for the resource. Note here, however, that the migration is called +create_blorgh_posts+ rather than the usual +create_posts+. This is due to the +isolate_namespace+ method called in the +Blorgh::Engine+ class's definition. The model here is also namespaced, being placed at +app/models/blorgh/post.rb+ rather than +app/models/post.rb+.
+
+Next, the +test_unit+ generator is invoked for this model, generating a unit test at +test/unit/blorgh/post_test.rb+ (rather than +test/unit/post_test.rb+) and a fixture at +test/fixtures/blorgh/posts.yml+ (rather than +test/fixtures/posts.yml+).
+
+After that, a line for the resource is inserted into the +config/routes.rb+ file for the engine. This line is simply +resources :posts+, turning the +config/routes.rb+ file into this:
+
+
+Blorgh::Engine.routes.draw do
+ resources :posts
+
+end
+
+
+Note here that the routes are drawn upon the +Blorgh::Engine+ object rather than the +YourApp::Application+ class. This is so that the engine routes are confined to the engine itself and can be mounted at a specific point as shown in the "test directory":#test-directory section.
+
TODO: Brief explanation of what this engine is going to be doing and what we will have once we are done.
TODO: Generate a posts scaffold (maybe?) for the engine
TODO: Generate a comments scaffold (maybe?) for the engine
--
cgit v1.2.3
From 765d3e955fdd4fec038c64bceacb60665a0aabbf Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 7 Oct 2011 09:56:50 +1100
Subject: [engines guide] Add TODO for mentioning rails s and rails c
---
railties/guides/source/engines.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 7b1c0a59e2..e131264842 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -156,6 +156,8 @@ TODO: Brief explanation of what this engine is going to be doing and what we wil
TODO: Generate a posts scaffold (maybe?) for the engine
TODO: Generate a comments scaffold (maybe?) for the engine
+TODO: Mention usage of `rails s` and `rails c` within the context of an engine.
+
h3. Hooking into application
TODO: Application will provide a User foundation class which the engine hooks into through a configuration setting, configurable in the application's initializers. The engine will be mounted at the +/blog+ path in the application.
--
cgit v1.2.3
From da030cf9cb335c2fd3deea3cdd474fa5c69fde48 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 7 Oct 2011 10:07:29 +1100
Subject: [engines guide] final line change
---
railties/guides/source/engines.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index e131264842..201dbd542e 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -165,4 +165,5 @@ TODO: Application will provide a User foundation class which the engine hooks in
h3. Overriding engine functionality
TODO: Cover how to override engine functionality in the engine, such as controllers and views.
-IDEA: I like Devise's +devise :controllers => { "sessions" => "sessions" }+ idea. Perhaps we could incorporate that into the guide?
\ No newline at end of file
+IDEA: I like Devise's +devise :controllers => { "sessions" => "sessions" }+ idea. Perhaps we could incorporate that into the guide?
+
--
cgit v1.2.3
From 9e6d43f9c9d7973aee9e1219aac00df3d3f49205 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Oct 2011 08:42:27 +1100
Subject: [engines guide] finish covering what the scaffold generator does
within an engine
---
railties/guides/source/engines.textile | 44 ++++++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 201dbd542e..b495b175e3 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -152,8 +152,48 @@ end
Note here that the routes are drawn upon the +Blorgh::Engine+ object rather than the +YourApp::Application+ class. This is so that the engine routes are confined to the engine itself and can be mounted at a specific point as shown in the "test directory":#test-directory section.
-TODO: Brief explanation of what this engine is going to be doing and what we will have once we are done.
-TODO: Generate a posts scaffold (maybe?) for the engine
+Next, the +scaffold_controller+ generator is invoked, generating a controlled called +Blorgh::PostsController+ (at +app/controllers/blorgh/posts_controller.rb+) and its related views at +app/views/blorgh/posts+. This generator also generates a functional test for the controller (+test/functional/blorgh/posts_controller_test.rb+) and a helper (+app/helpers/blorgh/posts_controller.rb+).
+
+Everything this generator has generated is neatly namespaced. The controller's class is defined within the +Blorgh+ module:
+
+
+module Blorgh
+ class PostsController < ApplicationController
+ ...
+ end
+end
+
+
+NOTE: The +ApplicationController+ class being inherited from here is the +Blorgh::ApplicationController+, not an application's +ApplicationController+.
+
+The helper is also namespaced:
+
+
+module Blorgh
+ class PostsHelper
+ ...
+ end
+end
+
+
+This helps prevent conflicts with any other engine or application that may have a post resource also.
+
+Finally, two files that are the assets for this resource are generated, +app/assets/javascripts/blorgh/posts.js+ and +app/assets/javascripts/blorgh/posts.css+. You'll see how to use these a little later.
+
+By default, the scaffold styling is not applied to the engine as the engine's layout file, +app/views/blorgh/application.html.erb+ doesn't load it. To make this apply, insert this line into the ++ tag of this layout:
+
+
+<%= stylesheet_link_tag "scaffold" %>
+
+
+You can see what the engine has so far by running +rake db:migrate+ at the root of our engine to run the migration generated by the scaffold generator, and then running +rails server+. When you open +http://localhost:3000/blorgh/posts+ you will see the default scaffold that has been generated.
+
+!images/engines_scaffold.png(Blank engine scaffold)!
+
+Click around! You've just generated your first engine's first functions.
+
+h4. Generating a comments resource
+
TODO: Generate a comments scaffold (maybe?) for the engine
TODO: Mention usage of `rails s` and `rails c` within the context of an engine.
--
cgit v1.2.3
From be01aa6c9b4adb4f95b2c86b13959d1bab16bc58 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Oct 2011 08:42:47 +1100
Subject: [engines guide] amend two TODOs for further things in this guide
---
railties/guides/source/engines.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index b495b175e3..f53611c310 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -196,7 +196,7 @@ h4. Generating a comments resource
TODO: Generate a comments scaffold (maybe?) for the engine
-TODO: Mention usage of `rails s` and `rails c` within the context of an engine.
+TODO: Mention usage of `rails c` within the context of an engine.
h3. Hooking into application
@@ -206,4 +206,5 @@ h3. Overriding engine functionality
TODO: Cover how to override engine functionality in the engine, such as controllers and views.
IDEA: I like Devise's +devise :controllers => { "sessions" => "sessions" }+ idea. Perhaps we could incorporate that into the guide?
+TODO: Mention how to use assets within an engine?
--
cgit v1.2.3
From 59c9825be5a570ef8d5cec1ec5bd9c6c06843f7e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Oct 2011 21:03:55 +1100
Subject: [engines guide] cover generating the comment resource
---
railties/guides/source/engines.textile | 86 +++++++++++++++++++++++++++++++++-
1 file changed, 84 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index f53611c310..e531bc7507 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -192,11 +192,93 @@ You can see what the engine has so far by running +rake db:migrate+ at the root
Click around! You've just generated your first engine's first functions.
+If you'd rather play around in the console, +rails console+ will also work just like a Rails application. Remember: the +Post+ model is namespaced, so to reference it you must call it as +Blorgh::Post+.
+
+
+ >> Blorgh::Post.find(1)
+ => #
+
+
h4. Generating a comments resource
-TODO: Generate a comments scaffold (maybe?) for the engine
+Now that the engine has the ability to create new blog posts, it only makes sense to add commenting functionality as well.
+
+To do this, you can run the scaffold generator this time and tell it to generate a +Comment+ resource instead, with the table having two columns: a +post_id+ integer and +text+ text column.
+
+
+$ rails generate scaffold Comment post_id:integer text:text
+
+
+This generator call will generate almost the same files as it did the first time we called it for generating the +Post+ resource, but this time the files will be called things such as +app/controllers/blorgh/comments_controller.rb+ and +app/models/blorgh/comment.rb+.
+
+There's a few things wrong with how this generator has worked. It would be better if the comments resource was nested inside the posts resource in the routes, and if the controller created new comment entries inside a post. These are two very easy things to fix up.
+
+The +resources+ line from this generator is placed into the +config/routes.rb+ by the generator, but you're going to want to have comments nested underneath a post, and so it's a good idea to change these lines in the +config/routes.rb+ file:
+
+
+Blorgh::Engine.routes.draw do
+ resources :comments
+
+ resources :posts
+
+end
+
+
+Into these:
+
+
+ Blorgh::Engine.routes.draw do
+ resources :posts do
+ resources :comments
+ end
+ end
+
+
+That fixes the routes. For the controller, it's just as easy. When a request is made to this controller, it will be in the form of +post/:post_id/comments+. In order to find the comments that are being requested, the post is going to need to be fetched using something such as:
+
+
+post = Post.find(params[:id])
+
+
+Then to get the comments for this post it would be as simple as:
+
+
+post.comments
+
+
+Alternatively, the query to fetch the comments in actions such as the +index+ action would need to be changed from +Comment.all+ into +Comment.find_all_by_post_id(params[:post_id])+. However, the first way is cleaner and so it should be done that way.
+
+To fetch the post in the controller, add a +before_filter+ into the controller's class definition like this:
+
+
+module Blorgh
+ class CommentsController < ApplicationController
+ before_filter :load_post
+ ...
+ end
+end
+
+
+This +before_filter+ will call the +load_post+ method before every request that comes into this controller. This method should be defined as a +private+ method after all the actions in the controller:
+
+
+module Blorgh
+ class CommentsController < ApplicationController
+ before_filter :load_post
+
+ # actions go here
+
+ private
+
+ def load_post
+ @post = Post.find(params[:post_id])
+ end
+ end
+end
+
+
+With the post being loaded, the queries in the controller need to be altered in order to query within the scope of the relative post. All occurrences of +Comment+ in this controller should now be replaced with +@post.comments+ so that the queries are correctly scoped.
-TODO: Mention usage of `rails c` within the context of an engine.
h3. Hooking into application
--
cgit v1.2.3
From 9c9583fa9be215875e6eacee3290dc46280f9a20 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Oct 2011 21:04:08 +1100
Subject: [engines guide] add TODO for RedCarpet example
---
railties/guides/source/engines.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index e531bc7507..db2db05e57 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -289,4 +289,4 @@ h3. Overriding engine functionality
TODO: Cover how to override engine functionality in the engine, such as controllers and views.
IDEA: I like Devise's +devise :controllers => { "sessions" => "sessions" }+ idea. Perhaps we could incorporate that into the guide?
TODO: Mention how to use assets within an engine?
-
+TODO: Mention how to depend on external gems, like RedCarpet.
--
cgit v1.2.3
From 16a0013d96e2078fc7b66f83fe46e8f0728fcb5c Mon Sep 17 00:00:00 2001
From: RAHUL CHAUDHARI
Date: Tue, 11 Oct 2011 10:26:22 +0530
Subject: Corrected typo
---
railties/guides/source/engines.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index db2db05e57..6be347e1a5 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -12,7 +12,7 @@ endprologue.
h3. What are engines?
-Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the +Rails::Application+ class inheriting from +Rails::Engine+. Therefore, engines and applications share common functionality but are at the same time two separate beasts. Engines and applications also share a common structure, as you'll see througout this guide.
+Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the +Rails::Application+ class inheriting from +Rails::Engine+. Therefore, engines and applications share common functionality but are at the same time two separate beasts. Engines and applications also share a common structure, as you'll see throughout this guide.
Engines are also closely related to plugins where the two share a common +lib+ directory structure and are both generated using the +rails plugin new+ generator.
--
cgit v1.2.3
From 1f62c6d09f44d080a508e18ec2c44c0adb61b76e Mon Sep 17 00:00:00 2001
From: RAHUL CHAUDHARI
Date: Tue, 11 Oct 2011 17:17:20 +0530
Subject: Fixed typos in active_support_core_extensions.textile
---
railties/guides/source/active_support_core_extensions.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index addf5f78be..ecc25c4f1c 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1760,7 +1760,7 @@ h4(#string-conversions). Conversions
h5. +ord+
-Ruby 1.9 defines +ord+ to be the codepoint of the first character of the receiver. Active Support backports +ord+ for single-byte encondings like ASCII or ISO-8859-1 in Ruby 1.8:
+Ruby 1.9 defines +ord+ to be the codepoint of the first character of the receiver. Active Support backports +ord+ for single-byte encodings like ASCII or ISO-8859-1 in Ruby 1.8:
"a".ord # => 97
@@ -1774,7 +1774,7 @@ In Ruby 1.8 +ord+ doesn't work in general in UTF8 strings, use the multibyte sup
"Ã ".mb_chars.ord # => 224, in UTF8
-Note that the 224 is different in both examples. In ISO-8859-1 "Ã " is represented as a single byte, 224. Its single-character representattion in UTF8 has two bytes, namely 195 and 160, but its Unicode codepoint is 224. If we call +ord+ on the UTF8 string "Ã " the return value will be 195 in Ruby 1.8. That is not an error, because UTF8 is unsupported, the call itself would be bogus.
+Note that the 224 is different in both examples. In ISO-8859-1 "Ã " is represented as a single byte, 224. Its single-character representation in UTF8 has two bytes, namely 195 and 160, but its Unicode codepoint is 224. If we call +ord+ on the UTF8 string "Ã " the return value will be 195 in Ruby 1.8. That is not an error, because UTF8 is unsupported, the call itself would be bogus.
INFO: +ord+ is equivalent to +getbyte(0)+.
--
cgit v1.2.3
From 3ca269674f66558f6ced4d956ecae4959dacd596 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Tue, 11 Oct 2011 06:27:01 -0700
Subject: Heavy copy editing of the find_each and find_in_batches section
---
.../guides/source/active_record_querying.textile | 60 ++++++++++++----------
1 file changed, 34 insertions(+), 26 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 81d73c4ccc..6ac9197f44 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -82,7 +82,7 @@ Active Record provides five different ways of retrieving a single object.
h5. Using a Primary Key
-Using Model.find(primary_key), you can retrieve the object corresponding to the supplied _primary key_ and matching the supplied options (if any). For example:
+Using Model.find(primary_key), you can retrieve the object corresponding to the specified _primary key_ that matches any supplied options. For example:
# Find the client with primary key (id) 10.
@@ -170,7 +170,7 @@ h4. Retrieving Multiple Objects
h5. Using Multiple Primary Keys
-Model.find(array_of_primary_key) also accepts an array of _primary keys_. An array of all the matching records for the supplied _primary keys_ is returned. For example:
+Model.find(array_of_primary_key) accepts an array of _primary keys_, returning an array containing all of the matching records for the supplied _primary keys_. For example:
# Find the clients with primary keys 1 and 10.
@@ -188,24 +188,26 @@ WARNING: Model.find(array_of_primary_key) will raise an +ActiveRecord::
h4. Retrieving Multiple Objects in Batches
-Sometimes you need to iterate over a large set of records. For example to send a newsletter to all users, to export some data, etc.
+We often need to iterate over a large set of records, as when we send a newsletter to a large set of users, or when we export data.
-The following may seem very straightforward, at first:
+This may appear straightforward:
-# Very inefficient when users table has thousands of rows.
+# This is very inefficient when the users table has thousands of rows.
User.all.each do |user|
NewsLetter.weekly_deliver(user)
end
-But if the total number of rows in the table is very large, the above approach may vary from being underperforming to being plain impossible.
+But this approach becomes increasingly impractical as the table size increases, since +User.all.each+ instructs Active Record to fetch _the entire table_ in a single pass, build a model object per row, and then keep the entire array of model objects in memory. Indeed, if we have a large number of records, the entire collection may exceed the amount of memory available.
-This is because +User.all.each+ makes Active Record fetch _the entire table_, build a model object per row, and keep the entire array of model objects in memory. Sometimes that is just too many objects and requires too much memory.
+Rails provides two methods that address this problem by dividing records into memory-friendly batches for processing. The first method, +find_each+, retrieves a batch of records and then yields _each_ record to the block individually as a model. The second method, +find_in_batches+, retrieves a batch of records and then yields _the entire batch_ to the block as an array of models.
+
+TIP: The +find_each+ and +find_in_batches+ methods are intended for use in the batch processing of a large number of records that wouldn't fit in memory all at once. If you just need to loop over a thousand records the regular find methods are the preferred option.
h5. +find_each+
-To efficiently iterate over a large table, Active Record provides a batch finder method called +find_each+:
+The +find_each+ method retrieves a batch of records and then yields _each_ record to the block individually as a model. In the following example, +find_each+ will retrieve 1000 records (the current default for both +find_each+ and +find_in_batches+) and then yield each record individually to the block as a model. This process is repeated until all of the records have been processed:
User.find_each do |user|
@@ -213,11 +215,15 @@ User.find_each do |user|
end
-*Configuring the batch size*
+h6. Options for +find_each+
+
+The +find_each+ method accepts most of the options allowed by the regular +find+ method, except for +:order+ and +:limit+, which are reserved for internal use by +find_each+.
-Behind the scenes, +find_each+ fetches rows in batches of 1000 and yields them one by one. The size of the underlying batches is configurable via the +:batch_size+ option.
+Two additional options, +:batch_size+ and +:start+, are available as well.
-To fetch +User+ records in batches of 5000, we can use:
+*+:batch_size+*
+
+The +:batch_size+ option allows you to specify the number of records to be retrieved in each batch, before being passed individually to the block. For example, to retrieve records in batches of 5000:
User.find_each(:batch_size => 5000) do |user|
@@ -225,37 +231,39 @@ User.find_each(:batch_size => 5000) do |user|
end
-*Starting batch find from a specific primary key*
+*+:start+*
-Records are fetched in ascending order of the primary key, which must be an integer. The +:start+ option allows you to configure the first ID of the sequence whenever the lowest ID is not the one you need. This may be useful, for example, to be able to resume an interrupted batch process, provided it saves the last processed ID as a checkpoint.
+By default, records are fetched in ascending order of the primary key, which must be an integer. The +:start+ option allows you to configure the first ID of the sequence whenever the lowest ID is not the one you need. This would be useful, for example, if you wanted to resume an interrupted batch process, provided you saved the last processed ID as a checkpoint.
-To send newsletters only to users with the primary key starting from 2000, we can use:
+For example, to send newsletters only to users with the primary key starting from 2000, and to retrieve them in batches of 5000:
-User.find_each(:batch_size => 5000, :start => 2000) do |user|
+User.find_each(:start => 2000, :batch_size => 5000) do |user|
NewsLetter.weekly_deliver(user)
end
-*Additional options*
+Another example would be if you wanted multiple workers handling the same processing queue. You could have each worker handle 10000 records by setting the appropriate :start option on each worker.
-+find_each+ accepts the same options as the regular +find+ method. However, +:order+ and +:limit+ are needed internally and hence not allowed to be passed explicitly.
+NOTE: The +:include+ option allows you to name associations that should be loaded alongside with the models.
h5. +find_in_batches+
-You can also work by chunks instead of row by row using +find_in_batches+. This method is analogous to +find_each+, but it yields arrays of models instead:
+The +find_in_batches+ method is similar to +find_each+, since both retrieve batches of records. The difference is that +find_in_batches+ yields _batches_ to the block as an array of models, instead of individually. The following example will yield to the supplied block an array of up to 1000 invoices at a time, with the final block containing any remaining invoices:
-# Works in chunks of 1000 invoices at a time.
+# Give add_invoices an array of 1000 invoices at a time
Invoice.find_in_batches(:include => :invoice_lines) do |invoices|
export.add_invoices(invoices)
end
-The above will each time yield to the supplied block an array of 1000 invoices (or the remaining invoices, if less than 1000).
-
NOTE: The +:include+ option allows you to name associations that should be loaded alongside with the models.
+h6. Options for +find_in_batches+
+
+The +find_in_batches+ method accepts the same +:batch_size+ and +:start+ options as +find_each+, as well as most of the options allowed by the regular +find+ method, except for +:order+ and +:limit+, which are reserved for internal use by +find_in_batches+.
+
h3. Conditions
The +where+ method allows you to specify conditions to limit the records returned, representing the +WHERE+-part of the SQL statement. Conditions can either be specified as a string, array, or hash.
@@ -268,7 +276,7 @@ WARNING: Building your own conditions as pure strings can leave you vulnerable t
h4. Array Conditions
-Now what if that number could vary, say as an argument from somewhere? The find then becomes something like:
+Now what if that number could vary, say as an argument from somewhere? The find would then take the form:
Client.where("orders_count = ?", params[:orders])
@@ -276,7 +284,7 @@ Client.where("orders_count = ?", params[:orders])
Active Record will go through the first element in the conditions value and any additional elements will replace the question marks +(?)+ in the first element.
-Or if you want to specify two conditions, you can do it like:
+If you want to specify multiple conditions:
Client.where("orders_count = ? AND locked = ?", params[:orders], false)
@@ -284,19 +292,19 @@ Client.where("orders_count = ? AND locked = ?", params[:orders], false)
In this example, the first question mark will be replaced with the value in +params[:orders]+ and the second will be replaced with the SQL representation of +false+, which depends on the adapter.
-The reason for doing code like:
+This code is highly preferable:
Client.where("orders_count = ?", params[:orders])
-instead of:
+to this code:
Client.where("orders_count = #{params[:orders]}")
-is because of argument safety. Putting the variable directly into the conditions string will pass the variable to the database *as-is*. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your arguments directly inside the conditions string.
+because of argument safety. Putting the variable directly into the conditions string will pass the variable to the database *as-is*. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your arguments directly inside the conditions string.
TIP: For more information on the dangers of SQL injection, see the "Ruby on Rails Security Guide":security.html#sql-injection.
--
cgit v1.2.3
From c4e29541724433fd1c96715bde829209066ca205 Mon Sep 17 00:00:00 2001
From: Stephen Pike
Date: Tue, 11 Oct 2011 09:32:23 -0400
Subject: Runtime conditions for associations should use procs
The association guide previously recommended using a trick with single
quote delaying of string interpolation in order to handle setting association
conditions that would be evaluated at runtime. Using a proc is the new way as
this no longer works.
---
railties/guides/source/association_basics.textile | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 479a3c1e30..6829eb8ef4 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -1229,17 +1229,15 @@ end
If you use a hash-style +:conditions+ option, then record creation via this association will be automatically scoped using the hash. In this case, using +@customer.confirmed_orders.create+ or +@customer.confirmed_orders.build+ will create orders where the confirmed column has the value +true+.
-If you need to evaluate conditions dynamically at runtime, you could use string interpolation in single quotes:
+If you need to evaluate conditions dynamically at runtime, use a proc:
class Customer < ActiveRecord::Base
has_many :latest_orders, :class_name => "Order",
- :conditions => 'orders.created_at > #{10.hours.ago.to_s(:db).inspect}'
+ :conditions => proc { "orders.created_at > #{10.hours.ago.to_s(:db).inspect}" }
end
-Be sure to use single quotes.
-
h6(#has_many-counter_sql). +:counter_sql+
Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself.
--
cgit v1.2.3
From 532e6d59b50b241d51d2a423bab5962d9cf7b0d4 Mon Sep 17 00:00:00 2001
From: Craig Monson
Date: Wed, 12 Oct 2011 10:34:27 -0400
Subject: quoting 'and' to make it more distinct.
---
railties/guides/source/active_record_querying.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 6ac9197f44..2e1f89cb78 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1024,7 +1024,7 @@ You can also use +find_last_by_*+ methods which will find the last record matchi
You can specify an exclamation point (!) on the end of the dynamic finders to get them to raise an +ActiveRecord::RecordNotFound+ error if they do not return any records, like +Client.find_by_name!("Ryan")+
-If you want to find both by name and locked, you can chain these finders together by simply typing +and+ between the fields. For example, +Client.find_by_first_name_and_locked("Ryan", true)+.
+If you want to find both by name and locked, you can chain these finders together by simply typing "+and+" between the fields. For example, +Client.find_by_first_name_and_locked("Ryan", true)+.
WARNING: Up to and including Rails 3.1, when the number of arguments passed to a dynamic finder method is lesser than the number of fields, say Client.find_by_name_and_locked("Ryan"), the behavior is to pass +nil+ as the missing argument. This is *unintentional* and this behavior will be changed in Rails 3.2 to throw an +ArgumentError+.
--
cgit v1.2.3
From e6b2e7fbeab495a9ce0533d3f778cca9cb268597 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 13 Oct 2011 02:17:01 +0530
Subject: refactor guide example
---
railties/guides/source/security.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index 0f100e0adf..8837e06de5 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -157,9 +157,9 @@ One possibility is to set the expiry time-stamp of the cookie with the session i
class Session < ActiveRecord::Base
def self.sweep(time = 1.hour)
- time = time.split.inject { |count, unit|
- count.to_i.send(unit)
- } if time.is_a?(String)
+ if time.is_a?(String)
+ time = time.split.inject { |count, unit| count.to_i.send(unit) }
+ end
delete_all "updated_at < '#{time.ago.to_s(:db)}'"
end
--
cgit v1.2.3
From e537a3fcb1fd16d169889dfbca13eece9cc3bdf1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Oct 2011 18:04:55 +1100
Subject: [engines guide] change comments resource generation
Totally didn't like where this section was going, so scrapped it.
Scaffold is great for some things (lol) but nested resources is definitely not one of them.
Best to walk people through how to do it right, as they would in the real world
---
railties/guides/source/engines.textile | 87 +++++++++++++---------------------
1 file changed, 33 insertions(+), 54 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index db2db05e57..e22f3a7ae6 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -201,83 +201,62 @@ If you'd rather play around in the console, +rails console+ will also work just
h4. Generating a comments resource
-Now that the engine has the ability to create new blog posts, it only makes sense to add commenting functionality as well.
+Now that the engine has the ability to create new blog posts, it only makes sense to add commenting functionality as well. To do get this, you'll need to generate a comment model, a comment controller and then modify the posts scaffold to display comments and allow people to create new ones.
-To do this, you can run the scaffold generator this time and tell it to generate a +Comment+ resource instead, with the table having two columns: a +post_id+ integer and +text+ text column.
+Run the model generator and tell it to generate a +Comment+ model, with the related table having two columns: a +post_id+ integer and +text+ text column.
-$ rails generate scaffold Comment post_id:integer text:text
+$ rails generate model Comment post_id:integer text:text
+invoke active_record
+create db/migrate/[timestamp]_create_blorgh_comments.rb
+create app/models/blorgh/comment.rb
+invoke test_unit
+create test/unit/blorgh/comment_test.rb
+create test/fixtures/blorgh/comments.yml
-This generator call will generate almost the same files as it did the first time we called it for generating the +Post+ resource, but this time the files will be called things such as +app/controllers/blorgh/comments_controller.rb+ and +app/models/blorgh/comment.rb+.
-
-There's a few things wrong with how this generator has worked. It would be better if the comments resource was nested inside the posts resource in the routes, and if the controller created new comment entries inside a post. These are two very easy things to fix up.
-
-The +resources+ line from this generator is placed into the +config/routes.rb+ by the generator, but you're going to want to have comments nested underneath a post, and so it's a good idea to change these lines in the +config/routes.rb+ file:
-
-
-Blorgh::Engine.routes.draw do
- resources :comments
-
- resources :posts
-
-end
-
-
-Into these:
-
-
- Blorgh::Engine.routes.draw do
- resources :posts do
- resources :comments
- end
- end
-
+This generator call will generate just the necessary model files it needs, namespacing the files under a +blorgh+ directory and creating a model class called +Blorgh::Comment+.
-That fixes the routes. For the controller, it's just as easy. When a request is made to this controller, it will be in the form of +post/:post_id/comments+. In order to find the comments that are being requested, the post is going to need to be fetched using something such as:
+To show the comments on a post, edit +app/views/posts/show.html.erb+ and add this line before the "Edit" link:
-
-post = Post.find(params[:id])
-
+
+<%= render @post.comments %>
+
-Then to get the comments for this post it would be as simple as:
+This line will require there to be a +has_many+ association for comments defined on the +Blorgh::Post+ model, which there isn't right now. To define one, open +app/models/blorgh/post.rb+ and add this line into the model:
-post.comments
+has_many :comments
-Alternatively, the query to fetch the comments in actions such as the +index+ action would need to be changed from +Comment.all+ into +Comment.find_all_by_post_id(params[:post_id])+. However, the first way is cleaner and so it should be done that way.
-
-To fetch the post in the controller, add a +before_filter+ into the controller's class definition like this:
+Turning the model into this:
module Blorgh
- class CommentsController < ApplicationController
- before_filter :load_post
- ...
+ class Post < ActiveRecord::Base
+ has_many :comments
end
end
-This +before_filter+ will call the +load_post+ method before every request that comes into this controller. This method should be defined as a +private+ method after all the actions in the controller:
-
-
-module Blorgh
- class CommentsController < ApplicationController
- before_filter :load_post
+Because the +has_many+ is defined inside a class that is inside the +Blorgh+ module, Rails will know that you want to use the +Blorgh::Comment+ model for these objects.
- # actions go here
+Next, there needs to be a form so that comments can be created on a post. To add this, put this line underneath the call to +render @post.comments+ in +app/views/blorgh/posts/show.html.erb+:
- private
+
+<%= render "comments/form" %>
+
- def load_post
- @post = Post.find(params[:post_id])
- end
- end
-end
-
+Next, the partial that this line will render needs to exist. Create a new directory at +app/views/blorgh/comments+ and in it a new file called +_form.html.erb+ with this content to create the required partial:
-With the post being loaded, the queries in the controller need to be altered in order to query within the scope of the relative post. All occurrences of +Comment+ in this controller should now be replaced with +@post.comments+ so that the queries are correctly scoped.
+
+<%= form_for [@post, @post.comments.build] do |f| %>
+
+<% end %>
+
h3. Hooking into application
--
cgit v1.2.3
From 66b2dc059f6c6649731e762b28b5136bf053daac Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Oct 2011 18:05:33 +1100
Subject: [engines guide] don't show actual timestamp in migration generation
---
railties/guides/source/engines.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index e22f3a7ae6..2366de33d7 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -107,7 +107,7 @@ The first thing to generate for a blog engine is the +Post+ model and related co
$ rails generate scaffold post title:string text:text
invoke active_record
-create db/migrate/20111006201642_create_blorgh_posts.rb
+create db/migrate/[timestamp]_create_blorgh_posts.rb
create app/models/blorgh/post.rb
invoke test_unit
create test/unit/blorgh/post_test.rb
--
cgit v1.2.3
From dadfa1e34f3ffbc2de98eae88b9715c41f4a1b66 Mon Sep 17 00:00:00 2001
From: PoTe
Date: Thu, 13 Oct 2011 22:31:32 -0200
Subject: security reasonS should be plural
---
railties/guides/source/action_controller_overview.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile
index d8d66302fe..5019d49686 100644
--- a/railties/guides/source/action_controller_overview.textile
+++ b/railties/guides/source/action_controller_overview.textile
@@ -796,7 +796,7 @@ NOTE: Certain exceptions are only rescuable from the +ApplicationController+ cla
h3. Force HTTPS protocol
-Sometime you might want to force a particular controller to only be accessible via an HTTPS protocol for security reason. Since Rails 3.1 you can now use +force_ssl+ method in your controller to enforce that:
+Sometime you might want to force a particular controller to only be accessible via an HTTPS protocol for security reasons. Since Rails 3.1 you can now use +force_ssl+ method in your controller to enforce that:
class DinnerController
--
cgit v1.2.3
From 411613ab207d6ff61520ad78a10b046469db9a80 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 14 Oct 2011 07:42:06 +1100
Subject: [engines guide] improve wording for sentence describing comments/form
partial
---
railties/guides/source/engines.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 2366de33d7..48c5cbf797 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -247,7 +247,7 @@ Next, there needs to be a form so that comments can be created on a post. To add
<%= render "comments/form" %>
-Next, the partial that this line will render needs to exist. Create a new directory at +app/views/blorgh/comments+ and in it a new file called +_form.html.erb+ with this content to create the required partial:
+Next, the partial that this line will render needs to exist. Create a new directory at +app/views/blorgh/comments+ and in it a new file called +_form.html.erb+ which has this content to create the required partial:
<%= form_for [@post, @post.comments.build] do |f| %>
--
cgit v1.2.3
From 690dd2f64c01985ece8690b9ac1c1ff2dfb6d968 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 14 Oct 2011 07:45:00 +1100
Subject: [engines guide] correct render line is blorgh/comments/form
---
railties/guides/source/engines.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 48c5cbf797..faa9dff8b8 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -244,7 +244,7 @@ Because the +has_many+ is defined inside a class that is inside the +Blorgh+ mod
Next, there needs to be a form so that comments can be created on a post. To add this, put this line underneath the call to +render @post.comments+ in +app/views/blorgh/posts/show.html.erb+:
-<%= render "comments/form" %>
+<%= render "blorgh/comments/form" %>
Next, the partial that this line will render needs to exist. Create a new directory at +app/views/blorgh/comments+ and in it a new file called +_form.html.erb+ which has this content to create the required partial:
--
cgit v1.2.3
From 2101bc9fd00f284ee5f86e72f35df9937289871b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 14 Oct 2011 07:51:07 +1100
Subject: [engines guide] make it clear that the scaffold generator output
isn't part of the actual command
---
railties/guides/source/engines.textile | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index faa9dff8b8..0df3889193 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -106,6 +106,11 @@ The first thing to generate for a blog engine is the +Post+ model and related co
$ rails generate scaffold post title:string text:text
+
+
+This command will output this information:
+
+
invoke active_record
create db/migrate/[timestamp]_create_blorgh_posts.rb
create app/models/blorgh/post.rb
@@ -207,12 +212,12 @@ Run the model generator and tell it to generate a +Comment+ model, with the rela
$ rails generate model Comment post_id:integer text:text
-invoke active_record
-create db/migrate/[timestamp]_create_blorgh_comments.rb
-create app/models/blorgh/comment.rb
-invoke test_unit
-create test/unit/blorgh/comment_test.rb
-create test/fixtures/blorgh/comments.yml
+ invoke active_record
+ create db/migrate/[timestamp]_create_blorgh_comments.rb
+ create app/models/blorgh/comment.rb
+ invoke test_unit
+ create test/unit/blorgh/comment_test.rb
+ create test/fixtures/blorgh/comments.yml
This generator call will generate just the necessary model files it needs, namespacing the files under a +blorgh+ directory and creating a model class called +Blorgh::Comment+.
--
cgit v1.2.3
From 2c8b8ce9eebce7f128d1811dde71f854fa8806c3 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 14 Oct 2011 07:51:45 +1100
Subject: [engines guide] make clear that the comment generator command is just
one line
---
railties/guides/source/engines.textile | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 0df3889193..f642781c04 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -212,12 +212,17 @@ Run the model generator and tell it to generate a +Comment+ model, with the rela
$ rails generate model Comment post_id:integer text:text
- invoke active_record
- create db/migrate/[timestamp]_create_blorgh_comments.rb
- create app/models/blorgh/comment.rb
- invoke test_unit
- create test/unit/blorgh/comment_test.rb
- create test/fixtures/blorgh/comments.yml
+
+
+This will output the following:
+
+
+invoke active_record
+create db/migrate/[timestamp]_create_blorgh_comments.rb
+create app/models/blorgh/comment.rb
+invoke test_unit
+create test/unit/blorgh/comment_test.rb
+create test/fixtures/blorgh/comments.yml
This generator call will generate just the necessary model files it needs, namespacing the files under a +blorgh+ directory and creating a model class called +Blorgh::Comment+.
--
cgit v1.2.3
From 3d192c73854b82fba313f641250f2e36031c87b7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 14 Oct 2011 18:05:45 +1100
Subject: [engines guide] Add heading for comments
---
railties/guides/source/engines.textile | 1 +
1 file changed, 1 insertion(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index f642781c04..616ea16b7a 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -230,6 +230,7 @@ This generator call will generate just the necessary model files it needs, names
To show the comments on a post, edit +app/views/posts/show.html.erb+ and add this line before the "Edit" link:
+
Comments
<%= render @post.comments %>
--
cgit v1.2.3
From aae77d2839349eb5034d6a72bfc351a532f1e6d7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 14 Oct 2011 18:06:23 +1100
Subject: [engines guide] complete comments resource generation
---
railties/guides/source/engines.textile | 65 ++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 616ea16b7a..12c454abd1 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -261,14 +261,79 @@ Next, there needs to be a form so that comments can be created on a post. To add
Next, the partial that this line will render needs to exist. Create a new directory at +app/views/blorgh/comments+ and in it a new file called +_form.html.erb+ which has this content to create the required partial:
+
New comment
<%= form_for [@post, @post.comments.build] do |f| %>
<%= f.label :text %>
<%= f.text_area :text %>
+ <%= f.submit %>
<% end %>
+This form, when submitted, is going to attempt to post to a route of +posts/:post_id/comments+ within the engine. This route doesn't exist at the moment, but can be created by changing the +resources :posts+ line inside +config/routes.rb+ into these lines:
+
+
+resources :posts do
+ resources :comments
+end
+
+
+The route now will exist, but the controller that this route goes to does not. To create it, run this command:
+
+
+$ rails g controller comments
+
+
+This will generate the following things:
+
+
+create app/controllers/blorgh/comments_controller.rb
+invoke erb
+ exist app/views/blorgh/comments
+invoke test_unit
+create test/functional/blorgh/comments_controller_test.rb
+invoke helper
+create app/helpers/blorgh/comments_helper.rb
+invoke test_unit
+create test/unit/helpers/blorgh/comments_helper_test.rb
+invoke assets
+invoke js
+create app/assets/javascripts/blorgh/comments.js
+invoke css
+create app/assets/stylesheets/blorgh/comments.css
+
+
+The form will be making a +POST+ request to +/posts/:post_id/comments+, which will correspond with the +create+ action in +Blorgh::CommentsController+. This action needs to be created and can be done by putting the following lines inside the class definition in +app/controllers/blorgh/comments_controller.rb+:
+
+
+def create
+ @post = Post.find(params[:post_id])
+ @comment = @post.comments.build(params[:comment])
+ flash[:notice] = "Comment has been created!"
+ redirect_to post_path
+end
+
+
+This is the final part required to get the new comment form working. Displaying the comments however, is not quite right yet. If you were to create a comment right now you would see this error:
+
+
+ Missing partial blorgh/comments/comment with {:handlers=>[:erb, :builder], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
+ * "/Users/ryan/Sites/side_projects/blorgh/test/dummy/app/views"
+ * "/Users/ryan/Sites/side_projects/blorgh/app/views"
+
+
+The engine is unable to find the partial required for rendering the comments. Rails has looked firstly in the application's (+test/dummy+) +app/views+ directory and then in the engine's +app/views+ directory. When it can't find it, it will throw this error. The engine knows to look for +blorgh/comments/comment+ because the model object it is receiving is from the +Blorgh::Comment+ class.
+
+This partial will be responsible for rendering just the comment text, for now. Create a new file at +app/views/blorgh/comments/_comment.html.erb+ and put this line inside it:
+
+
+<%= comment_counter + 1 %>. <%= comment.text %>
+
+
+The +comment_counter+ local variable is given to us by the +<%= render @post.comments %>+ call, as it will define this automatically and increment the counter as it iterates through each comment. It's used in this example to display a small number next to each comment when it's created.
+
+That completes the comment function of the blogging engine. Now it's time to use it within an application.
h3. Hooking into application
--
cgit v1.2.3
From 6df79bf580cf9a0464fce948c212bd117c378cc9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 14 Oct 2011 18:43:49 +1100
Subject: [engines guide] WIP for explaining how to hook engine into
application
---
railties/guides/source/engines.textile | 46 ++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 12c454abd1..1eb0dcb77b 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -204,6 +204,14 @@ If you'd rather play around in the console, +rails console+ will also work just
=> #
+One final thing is that the +posts+ resource for this engine should be the root of the engine. Whenever someone goes to the root path where the engine is mounted, they should be shown a list of posts. This can be made to happen if this line is inserted into the +config/routes.rb+ file inside the engine:
+
+
+root :to => "posts#index"
+
+
+Now people will only need to go to the root of the engine to see all the posts, rather than visiting +/posts+.
+
h4. Generating a comments resource
Now that the engine has the ability to create new blog posts, it only makes sense to add commenting functionality as well. To do get this, you'll need to generate a comment model, a comment controller and then modify the posts scaffold to display comments and allow people to create new ones.
@@ -337,11 +345,49 @@ That completes the comment function of the blogging engine. Now it's time to use
h3. Hooking into application
+Using an engine within an application is very easy. First, the engine needs to be specified inside the application's +Gemfile+. If there isn't an application handy to test this out in, generate one using the +rails new+ command outside of the engine directory like this:
+
+
+$ rails new unicorn
+
+
+Usually, specifying the engine inside the Gemfile would be done by specifying it as a normal, everyday gem.
+
+
+gem 'devise'
+
+
+Because the +blorgh+ engine is still under development, it will need to have a +:path+ option for its +Gemfile+ specification:
+
+
+gem 'blorgh', :path => "/path/to/blorgh"
+
+
+If the whole +blorgh+ engine directory is copied to +vendor/engines/blorgh+ then it could be specified in the +Gemfile+ like this:
+
+
+gem 'blorgh', :path => "vendor/engines/blorgh"
+
+
+As described earlier, by placing the gem in the +Gemfile+ it will be loaded when Rails is loaded, as it will first require +lib/blorgh.rb+ in the engine and then +lib/blorgh/engine.rb+, which is the file that defines the major pieces of functionality for the engine.
+
+To make the engine's functionality accessible from within an application, it needs to be mounted in that application's +config/routes.rb+ file:
+
+
+ mount Blorgh::Engine, :at => "blog"
+
+
+NOTE: Other engines, such as Devise, handle this a little differently by making you specify custom helpers such as +devise_for+ in the routes. These helpers do exactly the same thing, mounting pieces of the engines's functionality at a pre-defined path which may be customizable.
+
+
+
+This line will mount the engine
TODO: Application will provide a User foundation class which the engine hooks into through a configuration setting, configurable in the application's initializers. The engine will be mounted at the +/blog+ path in the application.
h3. Overriding engine functionality
TODO: Cover how to override engine functionality in the engine, such as controllers and views.
+
IDEA: I like Devise's +devise :controllers => { "sessions" => "sessions" }+ idea. Perhaps we could incorporate that into the guide?
TODO: Mention how to use assets within an engine?
TODO: Mention how to depend on external gems, like RedCarpet.
--
cgit v1.2.3
From 26204def8f28f190b9fef1144720288f87bd4fb4 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sat, 15 Oct 2011 05:32:13 -0700
Subject: [layouts and rendering] Copy editing to improve readability
---
.../guides/source/layouts_and_rendering.textile | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 69ef05104c..6f0dc57090 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -348,9 +348,9 @@ h5. Finding Layouts
To find the current layout, Rails first looks for a file in +app/views/layouts+ with the same base name as the controller. For example, rendering actions from the +PhotosController+ class will use +app/views/layouts/photos.html.erb+ (or +app/views/layouts/photos.builder+). If there is no such controller-specific layout, Rails will use +app/views/layouts/application.html.erb+ or +app/views/layouts/application.builder+. If there is no +.erb+ layout, Rails will use a +.builder+ layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.
-h6. Specifying Layouts on a per-Controller Basis
+h6. Specifying Layouts for Controllers
-You can override the automatic layout conventions in your controllers by using the +layout+ declaration in the controller. For example:
+You can override the default layout conventions in your controllers by using the +layout+ declaration. For example:
class ProductsController < ApplicationController
@@ -359,9 +359,9 @@ class ProductsController < ApplicationController
end
-With this declaration, all methods within +ProductsController+ will use +app/views/layouts/inventory.html.erb+ for their layout.
+With this declaration, all of the methods within +ProductsController+ will use +app/views/layouts/inventory.html.erb+ for their layout.
-To assign a specific layout for the entire application, use a declaration in your +ApplicationController+ class:
+To assign a specific layout for the entire application, use a +layout+ declaration in your +ApplicationController+ class:
class ApplicationController < ActionController::Base
@@ -370,7 +370,7 @@ class ApplicationController < ActionController::Base
end
-With this declaration, all views in the entire application will use +app/views/layouts/main.html.erb+ for their layout.
+With this declaration, all of the views in the entire application will use +app/views/layouts/main.html.erb+ for their layout.
h6. Choosing Layouts at Runtime
@@ -392,9 +392,9 @@ class ProductsController < ApplicationController
end
-Now, if the current user is a special user, they'll get a special layout when viewing a product. You can even use an inline method to determine the layout:
+Now, if the current user is a special user, they'll get a special layout when viewing a product.
-You can also decide the layout by passing a Proc object, the block you give the Proc will be given the +controller+ instance, so you can make decisions based on the current request. For example:
+You can even use an inline method, such as a Proc, to determine the layout. For example, if you pass a Proc object, the block you give the Proc will be given the +controller+ instance, so the layout can be determined based on the current request:
class ProductsController < ApplicationController
@@ -404,7 +404,7 @@ end
h6. Conditional Layouts
-Layouts specified at the controller level support +:only+ and +:except+ options that take either a method name or an array of method names which correspond to method names within the controller:
+Layouts specified at the controller level support the +:only+ and +:except+ options. These options take either a method name, or an array of method names, corresponding to method names within the controller:
class ProductsController < ApplicationController
@@ -416,7 +416,7 @@ With this declaration, the +product+ layout would be used for everything but the
h6. Layout Inheritance
-Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example:
+Layout declarations cascade downward in the hierarchy, and more specific layout declarations always override more general ones. For example:
* +application_controller.rb+
@@ -495,9 +495,9 @@ def show
end
-Make sure you use +and return+ and not +&& return+ because while the former will work, the latter will not due to operator precedence in the Ruby Language.
+Make sure to use +and return+ and not +&& return+, since +&& return+ will not work due to the operator precedence in the Ruby Language.
-Note that the implicit render done by ActionController detects if +render+ has been called, and thus avoids this error. Therefore, the following will work without errors:
+Note that the implicit render done by ActionController detects if +render+ has been called, so the following will work without errors:
def show
--
cgit v1.2.3
From 8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe Mon Sep 17 00:00:00 2001
From: Jose and Yehuda
Date: Mon, 26 Sep 2011 18:48:19 -0400
Subject: Initial commit of serializer support
---
railties/guides/source/serializers.textile | 600 +++++++++++++++++++++++++++++
1 file changed, 600 insertions(+)
create mode 100644 railties/guides/source/serializers.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
new file mode 100644
index 0000000000..a631a14694
--- /dev/null
+++ b/railties/guides/source/serializers.textile
@@ -0,0 +1,600 @@
+h2. Rails Serializers
+
+This guide describes how to use Active Model serializers to build non-trivial JSON services in Rails. By reading this guide, you will learn:
+
+* When to use the built-in Active Model serialization
+* When to use a custom serializer for your models
+* How to use serializers to encapsulate authorization concerns
+* How to create serializer templates to describe the application-wide structure of your serialized JSON
+* How to build resources not backed by a single database table for use with JSON services
+
+This guide covers an intermediate topic and assumes familiarity with Rails conventions. It is suitable for applications that expose a
+JSON API that may return different results based on the authorization status of the user.
+
+endprologue.
+
+h3. Serialization
+
+By default, Active Record objects can serialize themselves into JSON by using the `to_json` method. This method takes a series of additional
+parameter to control which properties and associations Rails should include in the serialized output.
+
+When building a web application that uses JavaScript to retrieve JSON data from the server, this mechanism has historically been the primary
+way that Rails developers prepared their responses. This works great for simple cases, as the logic for serializing an Active Record object
+is neatly encapsulated in Active Record itself.
+
+However, this solution quickly falls apart in the face of serialization requirements based on authorization. For instance, a web service
+may choose to expose additional information about a resource only if the user is entitled to access it. In addition, a JavaScript front-end
+may want information that is not neatly described in terms of serializing a single Active Record object, or in a different format than.
+
+In addition, neither the controller nor the model seems like the correct place for logic that describes how to serialize an model object
+*for the current user*.
+
+Serializers solve these problems by encapsulating serialization in an object designed for this purpose. If the default +to_json+ semantics,
+with at most a few configuration options serve your needs, by all means continue to use the built-in +to_json+. If you find yourself doing
+hash-driven-development in your controllers, juggling authorization logic and other concerns, serializers are for you!
+
+h3. The Most Basic Serializer
+
+A basic serializer is a simple Ruby object named after the model class it is serializing.
+
+
+class PostSerializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def as_json
+ { post: { title: @post.name, body: @post.body } }
+ end
+end
+
+
+A serializer is initialized with two parameters: the model object it should serialize and an authorization scope. By default, the
+authorization scope is the current user (+current_user+) but you can use a different object if you want. The serializer also
+implements an +as_json+ method, which returns a Hash that will be sent to the JSON encoder.
+
+Rails will transparently use your serializer when you use +render :json+ in your controller.
+
+
+class PostsController < ApplicationController
+ def show
+ @post = Post.find(params[:id])
+ render json: @post
+ end
+end
+
+
+Because +respond_with+ uses +render :json+ under the hood for JSON requests, Rails will automatically use your serializer when
+you use +respond_with+ as well.
+
+h4. +serializable_hash+
+
+In general, you will want to implement +serializable_hash+ and +as_json+ to allow serializers to embed associated content
+directly. The easiest way to implement these two methods is to have +as_json+ call +serializable_hash+ and insert the root.
+
+
+class PostSerializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def serializable_hash
+ { title: @post.name, body: @post.body }
+ end
+
+ def as_json
+ { post: serializable_hash }
+ end
+end
+
+
+h4. Authorization
+
+Let's update our serializer to include the email address of the author of the post, but only if the current user has superuser
+access.
+
+
+class PostSerializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def as_json
+ { post: serializable_hash }
+ end
+
+ def serializable_hash
+ hash = post
+ hash.merge!(super_data) if super?
+ hash
+ end
+
+private
+ def post
+ { title: @post.name, body: @post.body }
+ end
+
+ def super_data
+ { email: @post.email }
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+h4. Testing
+
+One benefit of encapsulating our objects this way is that it becomes extremely straight-forward to test the serialization
+logic in isolation.
+
+
+require "ostruct"
+
+class PostSerializerTest < ActiveSupport::TestCase
+ # For now, we use a very simple authorization structure. These tests will need
+ # refactoring if we change that.
+ plebe = OpenStruct.new(super?: false)
+ god = OpenStruct.new(super?: true)
+
+ post = OpenStruct.new(title: "Welcome to my blog!", body: "Blah blah blah", email: "tenderlove@gmail.com")
+
+ test "a regular user sees just the title and body" do
+ json = PostSerializer.new(post, plebe).to_json
+ hash = JSON.parse(json)
+
+ assert_equal post.title, hash.delete("title")
+ assert_equal post.body, hash.delete("body")
+ assert_empty hash
+ end
+
+ test "a superuser sees the title, body and email" do
+ json = PostSerializer.new(post, god).to_json
+ hash = JSON.parse(json)
+
+ assert_equal post.title, hash["title"]
+ assert_equal post.body, hash["body"]
+ assert_equal post.email, hash["email"]
+ assert_empty hash
+ end
+end
+
+
+It's important to note that serializer objects define a clear interface specifically for serializing an existing object.
+In this case, the serializer expects to receive a post object with +name+, +body+ and +email+ attributes and an authorization
+scope with a +super?+ method.
+
+By defining a clear interface, it's must easier to ensure that your authorization logic is behaving correctly. In this case,
+the serializer doesn't need to concern itself with how the authorization scope decides whether to set the +super?+ flag, just
+whether it is set. In general, you should document these requirements in your serializer files and programatically via tests.
+The documentation library +YARD+ provides excellent tools for describing this kind of requirement:
+
+
+class PostSerializer
+ # @param [~body, ~title, ~email] post the post to serialize
+ # @param [~super] scope the authorization scope for this serializer
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ # ...
+end
+
+
+h3. Attribute Sugar
+
+To simplify this process for a number of common cases, Rails provides a default superclass named +ActiveModel::Serializer+
+that you can use to implement your serializers.
+
+For example, you will sometimes want to simply include a number of existing attributes from the source model into the outputted
+JSON. In the above example, the +title+ and +body+ attributes were always included in the JSON. Let's see how to use
++ActiveModel::Serializer+ to simplify our post serializer.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title, :body
+
+ def initialize(post, scope)
+ @post, @scope = post, scope
+ end
+
+ def serializable_hash
+ hash = attributes
+ hash.merge!(super_data) if super?
+ hash
+ end
+
+private
+ def super_data
+ { email: @post.email }
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+First, we specified the list of included attributes at the top of the class. This will create an instance method called
++attributes+ that extracts those attributes from the post model.
+
+NOTE: Internally, +ActiveModel::Serializer+ uses +read_attribute_for_serialization+, which defaults to +read_attribute+, which defaults to +send+. So if you're rolling your own models for use with the serializer, you can use simple Ruby accessors for your attributes if you like.
+
+Next, we use the attributes methood in our +serializable_hash+ method, which allowed us to eliminate the +post+ method we hand-rolled
+earlier. We could also eliminate the +as_json+ method, as +ActiveModel::Serializer+ provides a default +as_json+ method for
+us that calls our +serializable_hash+ method and inserts a root. But we can go a step further!
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title, :body
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+The superclass provides a default +initialize+ method as well as a default +serializable_hash+ method, which uses
++attributes+. We can call +super+ to get the hash based on the attributes we declared, and then add in any additional
+attributes we want to use.
+
+NOTE: +ActiveModel::Serializer+ will create an accessor matching the name of the current class for the resource you pass in. In this case, because we have defined a PostSerializer, we can access the resource with the +post+ accessor.
+
+h3. Associations
+
+In most JSON APIs, you will want to include associated objects with your serialized object. In this case, let's include
+the comments with the current post.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+The default +serializable_hash+ method will include the comments as embedded objects inside the post.
+
+
+{
+ post: {
+ title: "Hello Blog!",
+ body: "This is my first post. Isn't it fabulous!",
+ comments: [
+ {
+ title: "Awesome",
+ body: "Your first post is great"
+ }
+ ]
+ }
+}
+
+
+Rails uses the same logic to generate embedded serializations as it does when you use +render :json+. In this case,
+because you didn't define a +CommentSerializer+, Rails used the default +as_json+ on your comment object.
+
+If you define a serializer, Rails will automatically instantiate it with the existing authorization scope.
+
+
+class CommentSerializer
+ def initialize(comment, scope)
+ @comment, @scope = comment, scope
+ end
+
+ def serializable_hash
+ { title: @comment.title }
+ end
+
+ def as_json
+ { comment: serializable_hash }
+ end
+end
+
+
+If we define the above comment serializer, the outputted JSON will change to:
+
+
+{
+ post: {
+ title: "Hello Blog!",
+ body: "This is my first post. Isn't it fabulous!",
+ comments: [{ title: "Awesome" }]
+ }
+}
+
+
+Let's imagine that our comment system allows an administrator to kill a comment, and we only want to allow
+users to see the comments they're entitled to see. By default, +has_many :comments+ will simply use the
++comments+ accessor on the post object. We can override the +comments+ accessor to limit the comments used
+to just the comments we want to allow for the current user.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def comments
+ post.comments_for(scope)
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
++ActiveModel::Serializer+ will still embed the comments, but this time it will use just the comments
+for the current user.
+
+NOTE: The logic for deciding which comments a user should see still belongs in the model layer. In general, you should encapsulate concerns that require making direct Active Record queries in scopes or public methods on your models.
+
+h3. Customizing Associations
+
+Not all front-ends expect embedded documents in the same form. In these cases, you can override the
+default +serializable_hash+, and use conveniences provided by +ActiveModel::Serializer+ to avoid having to
+build up the hash manually.
+
+For example, let's say our front-end expects the posts and comments in the following format:
+
+
+{
+ post: {
+ id: 1
+ title: "Hello Blog!",
+ body: "This is my first post. Isn't it fabulous!",
+ comments: [1,2]
+ },
+ comments: [
+ {
+ id: 1
+ title: "Awesome",
+ body: "Your first post is great"
+ },
+ {
+ id: 2
+ title: "Not so awesome",
+ body: "Why is it so short!"
+ }
+ ]
+}
+
+
+We could achieve this with a custom +as_json+ method. We will also need to define a serializer for comments.
+
+
+class CommentSerializer < ActiveModel::Serializer
+ attributes :id, :title, :body
+
+ # define any logic for dealing with authorization-based attributes here
+end
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments
+
+ def as_json
+ { post: serializable_hash }.merge!(associations)
+ end
+
+ def serializable_hash
+ post_hash = attributes
+ post_hash.merge!(association_ids)
+ post_hash
+ end
+
+private
+ def attributes
+ hash = super
+ hash.merge!(email: post.email) if super?
+ hash
+ end
+
+ def comments
+ post.comments_for(scope)
+ end
+
+ def super?
+ @scope.superuser?
+ end
+end
+
+
+Here, we used two convenience methods: +associations+ and +association_ids+. The first,
++associations+, creates a hash of all of the define associations, using their defined
+serializers. The second, +association_ids+, generates a hash whose key is the association
+name and whose value is an Array of the association's keys.
+
+The +association_ids+ helper will use the overridden version of the association, so in
+this case, +association_ids+ will only include the ids of the comments provided by the
++comments+ method.
+
+h3. Special Association Serializers
+
+So far, associations defined in serializers use either the +as_json+ method on the model
+or the defined serializer for the association type. Sometimes, you may want to serialize
+associated models differently when they are requested as part of another resource than
+when they are requested on their own.
+
+For instance, we might want to provide the full comment when it is requested directly,
+but only its title when requested as part of the post. To achieve this, you can define
+a serializer for associated objects nested inside the main serializer.
+
+
+class PostSerializer < ActiveModel::Serializer
+ class CommentSerializer < ActiveModel::Serializer
+ attributes :id, :title
+ end
+
+ # same as before
+ # ...
+end
+
+
+In other words, if a +PostSerializer+ is trying to serialize comments, it will first
+look for +PostSerializer::CommentSerializer+ before falling back to +CommentSerializer+
+and finally +comment.as_json+.
+
+h3. Optional Associations
+
+In some cases, you will want to allow a front-end to decide whether to include associated
+content or not. You can achieve this easily by making an association *optional*.
+
+
+class PostSerializer < ActiveModel::Serializer
+ attributes :title. :body
+ has_many :comments, :optional => true
+
+ # ...
+end
+
+
+If an association is optional, it will not be included unless the request asks for it
+with an +including+ parameter. The +including+ parameter is a comma-separated list of
+optional associations to include. If the +including+ parameter includes an association
+you did not specify in your serializer, it will receive a +401 Forbidden+ response.
+
+h3. Overriding the Defaults
+
+h4. Authorization Scope
+
+By default, the authorization scope for serializers is +:current_user+. This means
+that when you call +render json: @post+, the controller will automatically call
+its +current_user+ method and pass that along to the serializer's initializer.
+
+If you want to change that behavior, simply use the +serialization_scope+ class
+method.
+
+
+class PostsController < ApplicationController
+ serialization_scope :current_app
+end
+
+
+You can also implement an instance method called (no surprise) +serialization_scope+,
+which allows you to define a dynamic authorization scope based on the current request.
+
+WARNING: If you use different objects as authorization scopes, make sure that they all implement whatever interface you use in your serializers to control what the outputted JSON looks like.
+
+h4. Parameter to Specify Included Optional Associations
+
+In most cases, you should be able to use the default +including+ parameter to specify
+which optional associations to include. If you are already using that parameter name or
+want to reserve it for some reason, you can specify a different name by using the
++serialization_includes_param+ class method.
+
+
+class PostsController < ApplicationController
+ serialization_includes_param :associations_to_include
+end
+
+
+You can also implement a +serialization_includes+ instance method, which should return an
+Array of optional includes.
+
+WARNING: If you implement +serialization_includes+ and return an invalid association, your user will receive a +401 Forbidden+ exception.
+
+h3. Using Serializers Outside of a Request
+
+The serialization API encapsulates the concern of generating a JSON representation of
+a particular model for a particular user. As a result, you should be able to easily use
+serializers, whether you define them yourself or whether you use +ActiveModel::Serializer+
+outside a request.
+
+For instance, if you want to generate the JSON representation of a post for a user outside
+of a request:
+
+
+user = get_user # some logic to get the user in question
+PostSerializer.new(post, user).to_json # reliably generate JSON output
+
+
+If you want to generate JSON for an anonymous user, you should be able to use whatever
+technique you use in your application to generate anonymous users outside of a request.
+Typically, that means creating a new user and not saving it to the database:
+
+
+user = User.new # create a new anonymous user
+PostSerializer.new(post, user).to_json
+
+
+In general, the better you encapsulate your authorization logic, the more easily you
+will be able to use the serializer outside of the context of a request. For instance,
+if you use an authorization library like Cancan, which uses a uniform +user.can?(action, model)+,
+the authorization interface can very easily be replaced by a plain Ruby object for
+testing or usage outside the context of a request.
+
+h3. Collections
+
+So far, we've talked about serializing individual model objects. By default, Rails
+will serialize collections, including when using the +associations+ helper, by
+looping over each element of the collection, calling +serializable_hash+ on the element,
+and then grouping them by their type (using the plural version of their class name
+as the root).
+
+For example, an Array of post objects would serialize as:
+
+
+{
+ posts: [
+ {
+ title: "FIRST POST!",
+ body: "It's my first pooooost"
+ },
+ { title: "Second post!",
+ body: "Zomg I made it to my second post"
+ }
+ ]
+}
+
+
+If you want to change the behavior of serialized Arrays, you need to create
+a custom Array serializer.
+
+
+class ArraySerializer < ActiveModel::ArraySerializer
+ def serializable_array
+ serializers.map do |serializer|
+ serializer.serializable_hash
+ end
+ end
+
+ def as_json
+ hash = { root => serializable_array }
+ hash.merge!(associations)
+ hash
+ end
+end
+
+
+When generating embedded associations using the +associations+ helper inside a
+regular serializer, it will create a new ArraySerializer with the
+associated content and call its +serializable_array+ method. In this case, those
+embedded associations will not recursively include associations.
+
+When generating an Array using +render json: posts+, the controller will invoke
+the +as_json+ method, which will include its associations and its root.
--
cgit v1.2.3
From f5836543c3cd16f7789c936a4181f4a7204141dc Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 28 Sep 2011 17:05:03 +0530
Subject: minor edits in serializers guide
---
railties/guides/source/serializers.textile | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
index a631a14694..86a5e5ac8d 100644
--- a/railties/guides/source/serializers.textile
+++ b/railties/guides/source/serializers.textile
@@ -153,9 +153,9 @@ class PostSerializerTest < ActiveSupport::TestCase
json = PostSerializer.new(post, god).to_json
hash = JSON.parse(json)
- assert_equal post.title, hash["title"]
- assert_equal post.body, hash["body"]
- assert_equal post.email, hash["email"]
+ assert_equal post.title, hash.delete("title")
+ assert_equal post.body, hash.delete("body")
+ assert_equal post.email, hash.delete("email")
assert_empty hash
end
end
@@ -255,7 +255,7 @@ the comments with the current post.
class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
+ attributes :title, :body
has_many :comments
private
@@ -361,7 +361,7 @@ build up the hash manually.
For example, let's say our front-end expects the posts and comments in the following format:
-
+
{
post: {
id: 1
@@ -382,7 +382,7 @@ For example, let's say our front-end expects the posts and comments in the follo
}
]
}
-
+
We could achieve this with a custom +as_json+ method. We will also need to define a serializer for comments.
@@ -394,7 +394,7 @@ class CommentSerializer < ActiveModel::Serializer
end
class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
+ attributes :title, :body
has_many :comments
def as_json
@@ -558,7 +558,7 @@ as the root).
For example, an Array of post objects would serialize as:
-
+
{
posts: [
{
@@ -570,7 +570,7 @@ For example, an Array of post objects would serialize as:
}
]
}
-
+
If you want to change the behavior of serialized Arrays, you need to create
a custom Array serializer.
--
cgit v1.2.3
From abf4f096e56a941ac4f908cb34c83bc82770ed56 Mon Sep 17 00:00:00 2001
From: mhutchin
Date: Sat, 15 Oct 2011 15:59:26 -0700
Subject: [layouts and rendering] Copy editing
---
.../guides/source/layouts_and_rendering.textile | 52 +++++++++++-----------
1 file changed, 26 insertions(+), 26 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 6f0dc57090..df7b9b364c 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -334,7 +334,7 @@ render :status => 500
render :status => :forbidden
-Rails understands both numeric status codes and symbols for status codes.
+Rails understands both numeric and symbolic status codes.
h6. The +:location+ Option
@@ -518,7 +518,7 @@ Another way to handle returning responses to an HTTP request is with +redirect_t
redirect_to photos_url
-You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. In addition, there's a special redirect that sends the user back to the page they just came from:
+You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. There's also a special redirect that sends the user back to the page they just came from:
redirect_to :back
@@ -526,7 +526,7 @@ redirect_to :back
h5. Getting a Different Redirect Status Code
-Rails uses HTTP status code 302 (temporary redirect) when you call +redirect_to+. If you'd like to use a different status code (perhaps 301, permanent redirect), you can do so by using the +:status+ option:
+Rails uses HTTP status code 302, a temporary redirect, when you call +redirect_to+. If you'd like to use a different status code, perhaps 301, a permanent redirect, you can use the +:status+ option:
redirect_to photos_path, :status => 301
@@ -536,7 +536,7 @@ Just like the +:status+ option for +render+, +:status+ for +redirect_to+ accepts
h5. The Difference Between +render+ and +redirect_to+
-Sometimes inexperienced developers conceive of +redirect_to+ as a sort of +goto+ command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back an HTTP 302 status code.
+Sometimes inexperienced developers think of +redirect_to+ as a sort of +goto+ command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back an HTTP 302 status code.
Consider these actions to see the difference:
@@ -553,7 +553,7 @@ def show
end
-With the code in this form, there will likely be a problem if the +@book+ variable is +nil+. Remember, a +render :action+ doesn't run any code in the target action, so nothing will set up the +@books+ variable that the +index+ view is presumably depending on. One way to fix this is to redirect instead of rendering:
+With the code in this form, there will likely be a problem if the +@book+ variable is +nil+. Remember, a +render :action+ doesn't run any code in the target action, so nothing will set up the +@books+ variable that the +index+ view will probably require. One way to fix this is to redirect instead of rendering:
def index
@@ -570,9 +570,9 @@ end
With this code, the browser will make a fresh request for the index page, the code in the +index+ method will run, and all will be well.
-The only downside to this code, is that it requires a round trip to the browser, the browser requested the show action with +/books/1+ and the controller finds that there are no books, so the controller sends out a 302 redirect response to the browser telling it to go to +/books/+, the browser complies and sends a new request back to the controller asking now for the +index+ action, the controller then gets all the books in the database and renders the index template, sending it back down to the browser which then shows it on your screen.
+The only downside to this code is that it requires a round trip to the browser: the browser requested the show action with +/books/1+ and the controller finds that there are no books, so the controller sends out a 302 redirect response to the browser telling it to go to +/books/+, the browser complies and sends a new request back to the controller asking now for the +index+ action, the controller then gets all the books in the database and renders the index template, sending it back down to the browser which then shows it on your screen.
-While in a small app, this added latency might not be a problem, it is something to think about when speed of response is of the essence. One way to handle this double request (though a contrived example) could be:
+While in a small application, this added latency might not be a problem, it is something to think about if response time is a concern. We can demonstrate one way to handle this with a contrived example:
def index
@@ -588,7 +588,7 @@ def show
end
-Which would detect that there are no books, populate the +@books+ instance variable with all the books in the database and then directly render the +index.html.erb+ template returning it to the browser with a flash alert message telling the user what happened.
+This would detect that there are no books with the specified ID, populate the +@books+ instance variable with all the books in the model, and then directly render the +index.html.erb+ template, returning it to the browser with a flash alert message to tell the user what happened.
h4. Using +head+ To Build Header-Only Responses
@@ -598,7 +598,7 @@ The +head+ method can be used to send responses with only headers to the browser
head :bad_request
-Which would produce the following header:
+This would produce the following header:
HTTP/1.1 400 Bad Request
@@ -611,7 +611,7 @@ Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
Cache-Control: no-cache
-Or you can use other HTTP headers to convey additional information:
+Or you can use other HTTP headers to convey other information:
head :created, :location => photo_path(@photo)
@@ -633,15 +633,15 @@ Cache-Control: no-cache
h3. Structuring Layouts
-When Rails renders a view as a response, it does so by combining the view with the current layout (using the rules for finding the current layout that were covered earlier in this guide). Within a layout, you have access to three tools for combining different bits of output to form the overall response:
+When Rails renders a view as a response, it does so by combining the view with the current layout, using the rules for finding the current layout that were covered earlier in this guide. Within a layout, you have access to three tools for combining different bits of output to form the overall response:
* Asset tags
* +yield+ and +content_for+
* Partials
-h4. Asset Tags
+h4. Asset Tag Helpers
-Asset tags provide methods for generating HTML that links views to feeds, JavaScript, stylesheets, images, videos and audios. These are the six asset tags available in Rails:
+Asset tag helpers provide methods for generating HTML that link views to feeds, JavaScript, stylesheets, images, videos and audios. There are six asset tag helpers available in Rails:
* +auto_discovery_link_tag+
* +javascript_include_tag+
@@ -650,11 +650,11 @@ Asset tags provide methods for generating HTML that links views to feeds, JavaSc
* +video_tag+
* +audio_tag+
-You can use these tags in layouts or other views, although the tags other than +image_tag+ are most commonly used in the +<head>+ section of a layout.
+You can use these tags in layouts or other views, although the +auto_discovery_link_tag+, +javascript_include_tag+, and +stylesheet_link_tag+, are most commonly used in the +<head>+ section of a layout.
-WARNING: The asset tags do _not_ verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link.
+WARNING: The asset tag helpers do _not_ verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link.
-h5. Linking to Feeds with +auto_discovery_link_tag+
+h5. Linking to Feeds with the +auto_discovery_link_tag+
The +auto_discovery_link_tag+ helper builds HTML that most browsers and newsreaders can use to detect the presences of RSS or ATOM feeds. It takes the type of the link (+:rss+ or +:atom+), a hash of options that are passed through to url_for, and a hash of options for the tag:
@@ -663,13 +663,13 @@ The +auto_discovery_link_tag+ helper builds HTML that most browsers and newsread
{:title => "RSS Feed"}) %>
-There are three tag options available for +auto_discovery_link_tag+:
+There are three tag options available for the +auto_discovery_link_tag+:
-* +:rel+ specifies the +rel+ value in the link (defaults to "alternate")
+* +:rel+ specifies the +rel+ value in the link. The default value is "alternate".
* +:type+ specifies an explicit MIME type. Rails will generate an appropriate MIME type automatically.
-* +:title+ specifies the title of the link
+* +:title+ specifies the title of the link. The default value is the upshifted +:type+ value, for example, "ATOM" or "RSS".
-h5. Linking to JavaScript Files with +javascript_include_tag+
+h5. Linking to JavaScript Files with the +javascript_include_tag+
The +javascript_include_tag+ helper returns an HTML +script+ tag for each source provided. Rails looks in +public/javascripts+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/javascripts/main.js+:
@@ -738,7 +738,7 @@ By default, the combined file will be delivered as +javascripts/all.js+. You can
You can even use dynamic paths such as +cache/#{current_site}/main/display+.
-h5. Linking to CSS Files with +stylesheet_link_tag+
+h5. Linking to CSS Files with the +stylesheet_link_tag+
The +stylesheet_link_tag+ helper returns an HTML +<link>+ tag for each source provided. Rails looks in +public/stylesheets+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/stylesheets/main.css+:
@@ -764,7 +764,7 @@ To include +http://example.com/main.css+:
<%= stylesheet_link_tag "http://example.com/main.css" %>
-By default, +stylesheet_link_tag+ creates links with +media="screen" rel="stylesheet" type="text/css"+. You can override any of these defaults by specifying an appropriate option (+:media+, +:rel+, or +:type+):
+By default, the +stylesheet_link_tag+ creates links with +media="screen" rel="stylesheet" type="text/css"+. You can override any of these defaults by specifying an appropriate option (+:media+, +:rel+, or +:type+):
<%= stylesheet_link_tag "main_print", :media => "print" %>
@@ -797,7 +797,7 @@ By default, the combined file will be delivered as +stylesheets/all.css+. You ca
You can even use dynamic paths such as +cache/#{current_site}/main/display+.
-h5. Linking to Images with +image_tag+
+h5. Linking to Images with the +image_tag+
The +image_tag+ helper builds an HTML +<img />+ tag to the specified file. By default, files are loaded from +public/images+.
@@ -846,7 +846,7 @@ In addition to the above special tags, you can supply a final hash of standard H
:class => 'nav_bar' %>
-h5. Linking to Videos with +video_tag+
+h5. Linking to Videos with the +video_tag+
The +video_tag+ helper builds an HTML 5 +<video>+ tag to the specified file. By default, files are loaded from +public/videos+.
@@ -882,7 +882,7 @@ This will produce:
-h5. Linking to Audio files with +audio_tag+
+h5. Linking to Audio Files with the +audio_tag+
The +audio_tag+ helper builds an HTML 5 +<audio>+ tag to the specified file. By default, files are loaded from +public/audios+.
@@ -933,7 +933,7 @@ You can also create a layout with multiple yielding regions:
The main body of the view will always render into the unnamed +yield+. To render content into a named +yield+, you use the +content_for+ method.
-h4. Using +content_for+
+h4. Using the +content_for+ Method
The +content_for+ method allows you to insert content into a named +yield+ block in your layout. For example, this view would work with the layout that you just saw:
--
cgit v1.2.3
From bb8ee9264f8302ea9f669c96f46d9c3812d6f350 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Sat, 15 Oct 2011 09:51:30 +1100
Subject: [engines guide] improve intro to 'Hooking into an application'
section
---
railties/guides/source/engines.textile | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 126d09ab87..4f77852c40 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -343,9 +343,13 @@ The +comment_counter+ local variable is given to us by the +<%= render @post.com
That completes the comment function of the blogging engine. Now it's time to use it within an application.
-h3. Hooking into application
+h3. Hooking into an application
-Using an engine within an application is very easy. First, the engine needs to be specified inside the application's +Gemfile+. If there isn't an application handy to test this out in, generate one using the +rails new+ command outside of the engine directory like this:
+Using an engine within an application is very easy. This section covers how to mount the engine into an application and the initial setup required for it, as well as linking the engine to a +User+ class provided by the application to provide ownership for posts and comments within the engine.
+
+h4. Mounting the engine
+
+First, the engine needs to be specified inside the application's +Gemfile+. If there isn't an application handy to test this out in, generate one using the +rails new+ command outside of the engine directory like this:
$ rails new unicorn
--
cgit v1.2.3
From 0f87cc1486e2b7f95fff69ead9e6c74344c89496 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Sat, 15 Oct 2011 09:52:07 +1100
Subject: [engines guide] Add 'Engine setup' section in 'Hooking into an
application' section
---
railties/guides/source/engines.textile | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 4f77852c40..8d5c231124 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -378,14 +378,32 @@ As described earlier, by placing the gem in the +Gemfile+ it will be loaded when
To make the engine's functionality accessible from within an application, it needs to be mounted in that application's +config/routes.rb+ file:
- mount Blorgh::Engine, :at => "blog"
+mount Blorgh::Engine, :at => "blog"
+This line will mount the engine at +blog+ in the application. Making it accessible at +http://localhost:3000/blog+ when the application runs with +rails s+.
+
NOTE: Other engines, such as Devise, handle this a little differently by making you specify custom helpers such as +devise_for+ in the routes. These helpers do exactly the same thing, mounting pieces of the engines's functionality at a pre-defined path which may be customizable.
+h4. Engine setup
+
+The engine contains migrations for the +blorgh_posts+ and +blorgh_comments+ table which need to be created in the application's database so that the engine's models can query them correctly. To copy these migrations into the application use this command:
+
+
+$ rake blorgh:install:migrations
+
+
+This command, when run for the first time will copy over all the migrations from the engine. When run the next time, it will only copy over migrations that haven't been copied over already. The first run for this command will output something such as this:
+
+
+Copied migration [timestamp_1]_create_blorgh_posts.rb from blorgh
+Copied migration [timestamp_2]_create_blorgh_comments.rb from blorgh
+
+
+The first timestamp (+\[timestamp_1\]+) will be the current time and the second timestamp (+\[timestamp_2\]+) will be the current time plus a second. The reason for this is so that the migrations for the engine are run after any existing migrations in the application.
+To run these migrations within the context of the application, simply run +rake db:migrate+. When accessing the engine through +http://localhost:3000/blog+, the posts will be empty. This is because the table created inside the application is different from the one created within the engine. Go ahead, play around with the newly mounted engine. You'll find that it's the same as when it was only an engine.
-This line will mount the engine
TODO: Application will provide a User foundation class which the engine hooks into through a configuration setting, configurable in the application's initializers. The engine will be mounted at the +/blog+ path in the application.
h3. Overriding engine functionality
--
cgit v1.2.3
From 434148024d742ec50662bf72c5cbb8e5664985e5 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Sun, 16 Oct 2011 09:53:26 +1100
Subject: [engines guide] beginning to cover using application's classes
---
railties/guides/source/engines.textile | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 8d5c231124..9cdca25329 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -404,7 +404,29 @@ The first timestamp (+\[timestamp_1\]+) will be the current time and the second
To run these migrations within the context of the application, simply run +rake db:migrate+. When accessing the engine through +http://localhost:3000/blog+, the posts will be empty. This is because the table created inside the application is different from the one created within the engine. Go ahead, play around with the newly mounted engine. You'll find that it's the same as when it was only an engine.
-TODO: Application will provide a User foundation class which the engine hooks into through a configuration setting, configurable in the application's initializers. The engine will be mounted at the +/blog+ path in the application.
+h4. Using an application's classes
+
+When an engine is created, it may want to use specific classes from an application to provide links between the pieces of the engine and the pieces of the application. In the case of the +blorgh+ engine, making posts and comments have authors would make a lot of sense.
+
+Usually, an application would have a +User+ class that would provide the objects that would represent the posts' and comments' authors, but there could be a case where the application calls this class something different, such as +Person+. It's because of this reason that the engine should not hardcode the associations to be exactly for a +User+ class, but should allow for some flexibility around what the class is called.
+
+To keep it simple in this case, the application will have a class called +User+ which will represent the users of the application. It can be generated using this command:
+
+
+rails g model user name:string
+
+
+Also to keep it simple, the posts form will have a new text field called +author+ where users can elect to put their name. The engine will then take this name and create a new +User+ object from it or find one that already has that name, and then associate the post with it.
+
+First, the +author+ text field needs to be added to the +app/views/blorgh/posts/_form.html.erb+ partial inside the engine. This can be added above the +title+ field with this code:
+
+
+
+
+
h3. Overriding engine functionality
--
cgit v1.2.3
From 5bf0ea6830f9148f6b45d2774bfd7f54eec4a267 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 17 Oct 2011 08:55:32 +1100
Subject: [engines guide] Complete section about using an application's class
---
railties/guides/source/engines.textile | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 9cdca25329..bc5fe7640a 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -404,7 +404,7 @@ The first timestamp (+\[timestamp_1\]+) will be the current time and the second
To run these migrations within the context of the application, simply run +rake db:migrate+. When accessing the engine through +http://localhost:3000/blog+, the posts will be empty. This is because the table created inside the application is different from the one created within the engine. Go ahead, play around with the newly mounted engine. You'll find that it's the same as when it was only an engine.
-h4. Using an application's classes
+h4. Using a class provided by the application
When an engine is created, it may want to use specific classes from an application to provide links between the pieces of the engine and the pieces of the application. In the case of the +blorgh+ engine, making posts and comments have authors would make a lot of sense.
@@ -416,17 +416,38 @@ To keep it simple in this case, the application will have a class called +User+
rails g model user name:string
-Also to keep it simple, the posts form will have a new text field called +author+ where users can elect to put their name. The engine will then take this name and create a new +User+ object from it or find one that already has that name, and then associate the post with it.
+Also to keep it simple, the posts form will have a new text field called +author_name_+ where users can elect to put their name. The engine will then take this name and create a new +User+ object from it or find one that already has that name, and then associate the post with it.
-First, the +author+ text field needs to be added to the +app/views/blorgh/posts/_form.html.erb+ partial inside the engine. This can be added above the +title+ field with this code:
+First, the +author_name+ text field needs to be added to the +app/views/blorgh/posts/_form.html.erb+ partial inside the engine. This can be added above the +title+ field with this code:
+The +Blorgh::Post+ model should then have some code to convert the +author_name+ field into an actual +User+ object and associate it as that post's +author+ before the post is saved. It will also need to have an +attr_accessor+ setup for this field so that the setter and getter methods are defined for it.
+
+To do all this, you'll need to add the +attr_accessor+ for +author_name+, the association for the author and the +before_save+ call into +app/models/blorgh/post.rb+. The +author+ association will be hard-coded to the +User+ class for the time being.
+
+
+attr_accessor :author_name
+belongs_to :author, :class_name => "User"
+
+before_save :set_author
+
+private
+ def set_author
+ self.author = User.find_or_create_by_name(author_name)
+ end
+
+
+By defining that the +author+ association's object is represented by the +User+ class a link is established between the engine and the application. Now just before a post is saved it will be associated with a record from the +users+ table of the application.
+
+h4. Configuring an engine
+
+The next step is to make the class that represents a +User+ in the application customizable for the engine. This is because, as explained before, that class may not always be +User+.
h3. Overriding engine functionality
--
cgit v1.2.3
From 7d8c650e8663e0af722225e66f72a82dcb518b55 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 17 Oct 2011 17:12:31 +1100
Subject: [engines guide] [reviewing] remove excessive 'Now'
---
railties/guides/source/engines.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index bc5fe7640a..d191fe07b6 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -443,7 +443,7 @@ private
end
-By defining that the +author+ association's object is represented by the +User+ class a link is established between the engine and the application. Now just before a post is saved it will be associated with a record from the +users+ table of the application.
+By defining that the +author+ association's object is represented by the +User+ class a link is established between the engine and the application. Just before a post is saved it will be associated with a record from the +users+ table of the application.
h4. Configuring an engine
--
cgit v1.2.3
From 518b30cf486164c59b7120b7b5039aa85c962630 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 17 Oct 2011 20:25:45 +1100
Subject: [engines guide] Point out that we need to run rake db:migrate after
creating user model
---
railties/guides/source/engines.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index d191fe07b6..42c99d3405 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -416,6 +416,8 @@ To keep it simple in this case, the application will have a class called +User+
rails g model user name:string
+The +rake db:migrate+ command needs to be run here to ensure that our application has the +users+ table for future use.
+
Also to keep it simple, the posts form will have a new text field called +author_name_+ where users can elect to put their name. The engine will then take this name and create a new +User+ object from it or find one that already has that name, and then associate the post with it.
First, the +author_name+ text field needs to be added to the +app/views/blorgh/posts/_form.html.erb+ partial inside the engine. This can be added above the +title+ field with this code:
--
cgit v1.2.3
From cb95cca02674acf1f52d4c8f1a70fa22617e35d9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 17 Oct 2011 20:26:37 +1100
Subject: [engines guide] missed a spot in the 'Using a class section' +
further text for 'Configuring an engine' section
---
railties/guides/source/engines.textile | 71 +++++++++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 42c99d3405..6e27d823a7 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -445,11 +445,78 @@ private
end
-By defining that the +author+ association's object is represented by the +User+ class a link is established between the engine and the application. Just before a post is saved it will be associated with a record from the +users+ table of the application.
+By defining that the +author+ association's object is represented by the +User+ class a link is established between the engine and the application. There needs to be a way of associating the records in the +blorgh_posts+ table with the records in the +users+ table. Because the association is called +author+, there should be an +author_id+ column added to the +blorgh_posts+ table.
+
+To generate this new column, run this command within the engine:
+
+
+$ rails g migration add_author_to_blorgh_posts author:references
+
+
+NOTE: Due to the migration's name, Rails will automatically know that you want to add a column to a specific table and write that into the migration for you. You don't need to tell it any more than this.
+
+This migration will need to be run on the application. To do that, it must first be copied using this command:
+
+
+$ rake blorgh:install:migrations
+
+
+NOTE: Notice here that only _one_ migration was copied over here. This is because the first two migrations were copied over the first time this command was run.
+
+And then migrated using this command:
+
+
+$ rake db:migrate
+
+
+Now with all the pieces in place, an action will take place that will associate an author -- represented by a record in the +users+ table -- with a post, represented by the +blorgh_posts+ table from the engine.
+
+Finally, the author's name should be displayed on the post's page. Add this code above the "Title" output inside +app/views/blorgh/posts/show.html.erb+:
+
+
+
+ Author:
+ <%= @post.author.name %>
+
+
+
+NOTE: For posts created previously, this will break the +show+ page for them. We recommend deleting these posts and starting again, or manually assigning an author using +rails c+.
h4. Configuring an engine
-The next step is to make the class that represents a +User+ in the application customizable for the engine. This is because, as explained before, that class may not always be +User+.
+The next step is to make the class that represents a +User+ in the application customizable for the engine. This is because, as explained before, that class may not always be +User+. To make this customizable, the engine will have a configuration setting called +user_class+ that will be used to specify what the class representing users is inside the application.
+
+To define this configuration setting, you should use a +mattr_accessor+ inside the +Blorgh+ module for the engine, located at +lib/blorgh.rb+ inside the engine. Inside this module, put this line:
+
+
+mattr_accessor :user_class
+
+
+This method works like its brothers +attr_accessor+ and +cattr_accessor+, but provides a setter and getter method on the module with the specified name. To use it, it must be referenced using +Blorgh.user_class+.
+
+The next step is switching the +Blorgh::Post+ model over to this new setting. For the +belongs_to+ association inside this model (+app/models/blorgh/post.rb+), it will now become this:
+
+
+belongs_to :author, :class_name => Blorgh.user_class
+
+
+The +set_author+ method also located in this class should also use this class:
+
+
+self.author = Blorgh.user_class.constantize.find_or_create_by_name(author_name)
+
+
+To set this configuration setting within the application, an initializer should be used. By using an initializer, the configuration will be set up before the application starts and makes references to the classes of the engine which may depend on this configuration setting existing.
+
+Create a new initializer at +config/initializers/blorgh.rb+ inside the application where the +blorgh+ engine is installed and put this content in it:
+
+
+Blorgh.user_class = "User"
+
+
+WARNING: It's very important here to use the +String+ version of the class, rather than the class itself. If you were to use the class, Rails would attempt to load that class and then reference the related table, which could lead to problems if the table wasn't already existing. Therefore, a +String+ should be used and then converted to a class using +constantize+ in the engine later on.
+
+
h3. Overriding engine functionality
--
cgit v1.2.3
From 86919a6da17e164e6bb9e1f355052e552929141e Mon Sep 17 00:00:00 2001
From: Pascal Lindelauf
Date: Mon, 17 Oct 2011 14:45:45 +0200
Subject: Clarified that the config.assets.initialize_on_precompile directive
needs to be set in application.rb
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index afaf0f6fe3..6eb4ae49e3 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -349,7 +349,7 @@ bundle exec rake assets:precompile
For faster asset precompiles, you can partially load your application by setting
-+config.assets.initialize_on_precompile+ to false, though in that case templates
++config.assets.initialize_on_precompile+ to false in +config/application.rb+, though in that case templates
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
--
cgit v1.2.3
From 044e6ac245c24b91f7f815e2155bb7ac030ce831 Mon Sep 17 00:00:00 2001
From: Andy Lindeman
Date: Tue, 18 Oct 2011 23:45:56 -0300
Subject: Fixes the defaults for config.cache_classes
---
railties/guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index baf944cf8d..58b92e7f9e 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -64,7 +64,7 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is
* +config.autoload_paths+ accepts an array of paths from which Rails will autoload constants. Default is all directories under +app+.
-* +config.cache_classes+ controls whether or not application classes and modules should be reloaded on each request. Defaults to true in development mode, and false in test and production modes. Can also be enabled with +threadsafe!+.
+* +config.cache_classes+ controls whether or not application classes and modules should be reloaded on each request. Defaults to false in development mode, and true in test and production modes. Can also be enabled with +threadsafe!+.
* +config.action_view.cache_template_loading+ controls whether or not templates should be reloaded on each request. Defaults to whatever is set for +config.cache_classes+.
--
cgit v1.2.3
From afde6fdd5ef3e6b0693a7e330777e85ef4cffddb Mon Sep 17 00:00:00 2001
From: David Heinemeier Hansson
Date: Wed, 19 Oct 2011 12:59:33 -0500
Subject: Added X-Request-Id tracking and TaggedLogging to easily log that and
other production concerns
---
railties/guides/code/getting_started/config/environments/production.rb | 3 +++
1 file changed, 3 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/config/environments/production.rb b/railties/guides/code/getting_started/config/environments/production.rb
index 6ab63d30a6..4618191d6b 100644
--- a/railties/guides/code/getting_started/config/environments/production.rb
+++ b/railties/guides/code/getting_started/config/environments/production.rb
@@ -33,6 +33,9 @@ Blog::Application.configure do
# See everything in the log (default is :info)
# config.log_level = :debug
+ # Prepend all log lines with the following tags
+ # config.log_tags = [ :subdomain, :uuid ]
+
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
--
cgit v1.2.3
From 1359152345e84b951becf687ab6f26e30a9af3ce Mon Sep 17 00:00:00 2001
From: David Heinemeier Hansson
Date: Wed, 19 Oct 2011 16:16:44 -0500
Subject: Encourage use of tagged logging even when using a different logger
---
railties/guides/code/getting_started/config/environments/production.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/config/environments/production.rb b/railties/guides/code/getting_started/config/environments/production.rb
index 4618191d6b..dee8acfdfe 100644
--- a/railties/guides/code/getting_started/config/environments/production.rb
+++ b/railties/guides/code/getting_started/config/environments/production.rb
@@ -37,7 +37,7 @@ Blog::Application.configure do
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
- # config.logger = SyslogLogger.new
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
--
cgit v1.2.3
From 9694ca1a3bd070886802a6b9f7532adfe5b60cc4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 19 Oct 2011 18:26:19 +1100
Subject: [engines guide] mention that we cover similar ground to the Getting
Started Guide
---
railties/guides/source/engines.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 6e27d823a7..73bbe486e5 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -98,7 +98,7 @@ Also in the test directory is the +test/integration+ directory, where integratio
h3. Providing engine functionality
-The engine that this guide covers will provide posting and commenting functionality.
+The engine that this guide covers will provide posting and commenting functionality and follows a similar thread to the "Getting Started Guide":getting-started.html, with some new twists.
h4. Generating a post resource
--
cgit v1.2.3
From 8ede74e73a45b16a81064a175b3174848469498b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 20 Oct 2011 08:46:20 +1100
Subject: [engines guide] Rather than calling name, require a to_s method to be
defined on the 'User' class
---
railties/guides/source/engines.textile | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 73bbe486e5..02054c972a 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -476,11 +476,26 @@ Finally, the author's name should be displayed on the post's page. Add this code
-NOTE: For posts created previously, this will break the +show+ page for them. We recommend deleting these posts and starting again, or manually assigning an author using +rails c+.
+WARNING: For posts created previously, this will break the +show+ page for them. We recommend deleting these posts and starting again, or manually assigning an author using +rails c+.
+
+By outputting +@post.author+ using the +<%=+ tag the +to_s+ method will be called on the object. By default, this will look quite ugly:
+
+
+#
+
+
+This is undesirable and it would be much better to have the user's name there. To do this, add a +to_s+ method to the +User+ class within the application:
+
+
+def to_s
+ name
+
+
+Now instead of the ugly Ruby object output the author's name will be displayed.
h4. Configuring an engine
--
cgit v1.2.3
From 1cc6105d4dd088e3f2b8026e7e49f4e9d8d7d6ea Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 20 Oct 2011 08:46:41 +1100
Subject: [engines guide] wrap up 'Configuring an Engine' section
---
railties/guides/source/engines.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 02054c972a..f0d8f1a165 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -531,7 +531,9 @@ Blorgh.user_class = "User"
WARNING: It's very important here to use the +String+ version of the class, rather than the class itself. If you were to use the class, Rails would attempt to load that class and then reference the related table, which could lead to problems if the table wasn't already existing. Therefore, a +String+ should be used and then converted to a class using +constantize+ in the engine later on.
+Go ahead and try to create a new post. You will see that it works exactly in the same way as before, except this time the engine is using the configuration setting in +config/initializers/blorgh.rb+ to learn what the class is.
+There are now no strict dependencies on what the class is, only what the class's API must be. The engine simply requires this class to define a +find_or_create_by_name+ method which returns an object of that class to be associated with a post when it's created.
h3. Overriding engine functionality
--
cgit v1.2.3
From 3e2d35b05006099163f6492019536bbfa1d82509 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 20 Oct 2011 17:10:46 +1100
Subject: [engines guide] add missing end for to_s method
---
railties/guides/source/engines.textile | 1 +
1 file changed, 1 insertion(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index f0d8f1a165..5a12896b8e 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -493,6 +493,7 @@ This is undesirable and it would be much better to have the user's name there. T
def to_s
name
+end
Now instead of the ugly Ruby object output the author's name will be displayed.
--
cgit v1.2.3
From 13e6f0cea83b2699e76b4f21ff87b267514d18d6 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 20 Oct 2011 17:32:34 +1100
Subject: [engines guide] some fixes for the author id migration including
proof of not copying over other migrations again
---
railties/guides/source/engines.textile | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 5a12896b8e..0688dc4c99 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -450,10 +450,10 @@ By defining that the +author+ association's object is represented by the +User+
To generate this new column, run this command within the engine:
-$ rails g migration add_author_to_blorgh_posts author:references
+$ rails g migration add_author_id_to_blorgh_posts author_id:integer
-NOTE: Due to the migration's name, Rails will automatically know that you want to add a column to a specific table and write that into the migration for you. You don't need to tell it any more than this.
+NOTE: Due to the migration's name and the column specification after it, Rails will automatically know that you want to add a column to a specific table and write that into the migration for you. You don't need to tell it any more than this.
This migration will need to be run on the application. To do that, it must first be copied using this command:
@@ -461,9 +461,15 @@ This migration will need to be run on the application. To do that, it must first
$ rake blorgh:install:migrations
-NOTE: Notice here that only _one_ migration was copied over here. This is because the first two migrations were copied over the first time this command was run.
+Notice here that only _one_ migration was copied over here. This is because the first two migrations were copied over the first time this command was run.
-And then migrated using this command:
+
+ NOTE: Migration [timestamp]_create_blorgh_posts.rb from blorgh has been skipped. Migration with the same name already exists.
+ NOTE: Migration [timestamp]_create_blorgh_comments.rb from blorgh has been skipped. Migration with the same name already exists.
+ Copied migration [timestamp]_add_author_id_to_blorgh_posts.rb from blorgh
+
+
+Run this migration using this command:
$ rake db:migrate
--
cgit v1.2.3
From ee1223c1ee90899819a88c39db3e77b3692c68ee Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 20 Oct 2011 18:30:50 +1100
Subject: [engines guide] explanation of overriding views + referencing routes
from an engine within an application
---
railties/guides/source/engines.textile | 59 ++++++++++++++++++++++++++++++++--
1 file changed, 57 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index 0688dc4c99..da56f3d0ed 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -542,10 +542,65 @@ Go ahead and try to create a new post. You will see that it works exactly in the
There are now no strict dependencies on what the class is, only what the class's API must be. The engine simply requires this class to define a +find_or_create_by_name+ method which returns an object of that class to be associated with a post when it's created.
-h3. Overriding engine functionality
+h3. Extending engine functionality
-TODO: Cover how to override engine functionality in the engine, such as controllers and views.
+This section looks at overriding or adding functionality to the views, controllers and models provided by an engine.
+h4. Overriding views
+
+When Rails looks for a view to render, it will first look in the +app/views+ directory of the application. If it cannot find the view there, then it will check in the +app/views+ directories of all engines which have this directory.
+
+In the +blorgh+ engine, there is a currently a file at +app/views/blorgh/posts/index.html.erb+. When the engine is asked to render the view for +Blorgh::PostsController+'s +index+ action, it will first see if it can find it at +app/views/blorgh/posts/index.html.erb+ within the application and then if it cannot it will look inside the engine.
+
+By overriding this view in the application, by simply creating a new file at +app/views/blorgh/posts/index.html.erb+, you can completely change what this view would normally output.
+
+Try this now by creating a new file at +app/views/blorgh/posts/index.html.erb+ and put this content in it:
+
+
+
Posts
+<%= link_to "New Post", new_post_path %>
+<% @posts.each do |post| %>
+
<%= post.title %>
+ By <%= post.author %>
+ <%= simple_format(post.text) %>
+
+<% end %>
+
+
+Rather than looking like the default scaffold, the page will now look like this:
+
+!images/engines_post_override.png(Engine scaffold overriden)!
+
+h4. Controllers
+
+TODO: Explain how to extend a controller.
IDEA: I like Devise's +devise :controllers => { "sessions" => "sessions" }+ idea. Perhaps we could incorporate that into the guide?
+
+h4. Models
+
+TODO: Explain how to extend models provided by an engine.
+
+h4. Routes
+
+Within the application, you may wish to link to some area within the engine. Due to the fact that the engine's routes are isolated (by the +isolate_namespace+ call within the +lib/blorgh/engine.rb+ file), you will need to prefix these routes with the engine name. This means rather than having something such as:
+
+
+<%= link_to "Blog posts", posts_path %>
+
+
+It needs to be written as:
+
+
+<%= link_to "Blog posts", blorgh.posts_path %>
+
+
+This allows for the engine _and_ the application to both have a +posts_path+ routing helper and to not interfere with each other. You may also reference another engine's routes from inside an engine using this same syntax.
+
+If you wish to reference the application inside the engine in a similar way, use the +main_app+ helper:
+
+
+<%= link_to "Home", main_app.root_path %>
+
+
TODO: Mention how to use assets within an engine?
TODO: Mention how to depend on external gems, like RedCarpet.
--
cgit v1.2.3
From 48e1f8ba4c02ed81ba70fee459de8bc569197fc4 Mon Sep 17 00:00:00 2001
From: Pepe Hipolito
Date: Thu, 20 Oct 2011 15:37:35 -0400
Subject: Fixed typo.
a long the way => along the way
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 32b41fdd2c..2299573a9f 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -7,7 +7,7 @@ This guide explains the internals of the initialization process in Rails as of R
endprologue.
-This guide goes through every single file, class and method call that is required to boot up the Ruby on Rails stack for a default Rails 3.1 application, explaining each part in detail a long the way. For this guide, we will be focusing on how the two most common methods (+rails server+ and Passenger) boot a Rails application.
+This guide goes through every single file, class and method call that is required to boot up the Ruby on Rails stack for a default Rails 3.1 application, explaining each part in detail along the way. For this guide, we will be focusing on how the two most common methods (+rails server+ and Passenger) boot a Rails application.
NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified.
--
cgit v1.2.3
From 0cd93a6e2bbcdd2ead0d6e4b739dfd8def04d8d5 Mon Sep 17 00:00:00 2001
From: Pepe Hipolito
Date: Thu, 20 Oct 2011 15:58:51 -0400
Subject: Fixed typo.
Ruby will know to look for this file at => Ruby will know how to look for this file at
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 2299573a9f..f88405a2fd 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -243,7 +243,7 @@ In this file there are a lot of lines such as this inside the +ActiveSupport+ mo
autoload :Inflector
-Due to the overriding of the +autoload+ method, Ruby will know to look for this file at +activesupport/lib/active_support/inflector.rb+ when the +Inflector+ class is first referenced.
+Due to the overriding of the +autoload+ method, Ruby will know how to look for this file at +activesupport/lib/active_support/inflector.rb+ when the +Inflector+ class is first referenced.
The +active_support/lib/active_support/version.rb+ that is also required here simply defines an +ActiveSupport::VERSION+ constant which defines a couple of constants inside this module, the main constant of this is +ActiveSupport::VERSION::STRING+ which returns the current version of ActiveSupport.
--
cgit v1.2.3
From 2b04c2f66e3cf5abbbf118eaa1e692b9e1380e4e Mon Sep 17 00:00:00 2001
From: Brian Durand
Date: Fri, 21 Oct 2011 13:13:29 -0500
Subject: Add ActionDispatch::Session::CacheStore as a generic way of storing
sessions in a cache.
---
railties/guides/source/action_controller_overview.textile | 10 ++++++----
railties/guides/source/rails_on_rack.textile | 5 +++--
railties/guides/source/security.textile | 4 ++--
3 files changed, 11 insertions(+), 8 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile
index 5019d49686..b34c223b31 100644
--- a/railties/guides/source/action_controller_overview.textile
+++ b/railties/guides/source/action_controller_overview.textile
@@ -166,10 +166,10 @@ h3. Session
Your application has a session for each user in which you can store small amounts of data that will be persisted between requests. The session is only available in the controller and the view and can use one of a number of different storage mechanisms:
-* CookieStore - Stores everything on the client.
-* DRbStore - Stores the data on a DRb server.
-* MemCacheStore - Stores the data in a memcache.
-* ActiveRecordStore - Stores the data in a database using Active Record.
+* ActionDispatch::Session::CookieStore - Stores everything on the client.
+* ActiveRecord::SessionStore - Stores the data in a database using Active Record.
+* ActionDispatch::Session::CacheStore - Stores the data in the Rails cache.
+* ActionDispatch::Session::MemCacheStore - Stores the data in a memcached cluster (this is a legacy implementation; consider using CacheStore instead).
All session stores use a cookie to store a unique ID for each session (you must use a cookie, Rails will not allow you to pass the session ID in the URL as this is less secure).
@@ -177,6 +177,8 @@ For most stores this ID is used to look up the session data on the server, e.g.
The CookieStore can store around 4kB of data -- much less than the others -- but this is usually enough. Storing large amounts of data in the session is discouraged no matter which session store your application uses. You should especially avoid storing complex objects (anything other than basic Ruby objects, the most common example being model instances) in the session, as the server might not be able to reassemble them between requests, which will result in an error.
+If your user sessions don't store critical data or don't need to be around for long periods (for instance if you just use the flash for messaging), you can consider using ActionDispatch::Session::CacheStore. This will store sessions using the cache implementation you have configured for your application. The advantage of this is that you can use your existing cache infrastructure for storing sessions without requiring any additional setup or administration. The downside, of course, is that the sessions will be ephemeral and could disappear at any time.
+
Read more about session storage in the "Security Guide":security.html.
If you need a different session storage mechanism, you can change it in the +config/initializers/session_store.rb+ file:
diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index 57c03b54dc..d6cbd84b1f 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -166,8 +166,9 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
|+Rack::Lock+|Sets env["rack.multithread"] flag to +true+ and wraps the application within a Mutex.|
|+ActionController::Failsafe+|Returns HTTP Status +500+ to the client if an exception gets raised while dispatching.|
|+ActiveRecord::QueryCache+|Enables the Active Record query cache.|
-|+ActionController::Session::CookieStore+|Uses the cookie based session store.|
-|+ActionController::Session::MemCacheStore+|Uses the memcached based session store.|
+|+ActionDispatch::Session::CookieStore+|Uses the cookie based session store.|
+|+ActionDispatch::Session::CacheStore+|Uses the Rails cache based session store.|
+|+ActionDispatch::Session::MemCacheStore+|Uses the memcached based session store.|
|+ActiveRecord::SessionStore+|Uses the database based session store.|
|+Rack::MethodOverride+|Sets HTTP method based on +_method+ parameter or env["HTTP_X_HTTP_METHOD_OVERRIDE"].|
|+Rack::Head+|Discards the response body if the client sends a +HEAD+ request.|
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index 8837e06de5..a499ef3d39 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -82,9 +82,9 @@ This will also be a good idea, if you modify the structure of an object and old
h4. Session Storage
--- _Rails provides several storage mechanisms for the session hashes. The most important are SessionStore and CookieStore._
+-- _Rails provides several storage mechanisms for the session hashes. The most important are ActiveRecord::SessionStore and ActionDispatch::Session::CookieStore._
-There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose SessionStore (or one of its derivatives) over file storage due to performance and maintenance reasons. SessionStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.
+There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose ActiveRecord::SessionStore (or one of its derivatives) over file storage due to performance and maintenance reasons. ActiveRecord::SessionStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.
Rails 2 introduced a new default session storage, CookieStore. CookieStore saves the session hash directly in a cookie on the client-side. The server retrieves the session hash from the cookie and eliminates the need for a session id. That will greatly increase the speed of the application, but it is a controversial storage option and you have to think about the security implications of it:
--
cgit v1.2.3
From ec93f363cab7270c1469b420a52a21e306a89c30 Mon Sep 17 00:00:00 2001
From: Brian Durand
Date: Fri, 21 Oct 2011 13:28:24 -0500
Subject: Fix ActiveSupport::Cache::FileStore.cleanup to actually work.
---
railties/guides/source/caching_with_rails.textile | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 4273d0dd64..721c791a33 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -289,7 +289,11 @@ ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"
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.
-Note that the cache will grow until the disk is full unless you periodically clear out old entries.
+Note that the cache will grow until the disk is full unless you periodically clear out old entries. You can call +ActiveSupport::Cache::FileStore#cleanup+ to remove entries older than a specified time.
+
+
+Rails.cache.cleanup(:not_accessed_in => 2.days)
+
h4. ActiveSupport::Cache::MemCacheStore
--
cgit v1.2.3
From 50be4231e9bd475cda905ab489d4bfc9ebd887f7 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sat, 22 Oct 2011 15:51:55 +0530
Subject: Middleware details updated for 3.2
---
railties/guides/source/command_line.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index f6b33d283c..d3f73e06e0 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -389,7 +389,7 @@ Action Pack version 3.1.0
Active Resource version 3.1.0
Action Mailer version 3.1.0
Active Support version 3.1.0
-Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
+Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root /home/foobar/commandsapp
Environment development
Database adapter sqlite3
--
cgit v1.2.3
From 6d5b92c735130a99186ef6f2ce6abe3f8745a8a5 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sat, 22 Oct 2011 15:53:11 +0530
Subject: Rails version to 3.2.0.beta in docs
---
railties/guides/source/command_line.textile | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index d3f73e06e0..ffa198891a 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -382,13 +382,13 @@ About your application's environment
Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.3.6
Rack version 1.1
-Rails version 3.1.0
+Rails version 3.2.0.beta
JavaScript Runtime Node.js (V8)
-Active Record version 3.1.0
-Action Pack version 3.1.0
-Active Resource version 3.1.0
-Action Mailer version 3.1.0
-Active Support version 3.1.0
+Active Record version 3.2.0.beta
+Action Pack version 3.2.0.beta
+Active Resource version 3.2.0.beta
+Action Mailer version 3.2.0.beta
+Active Support version 3.2.0.beta
Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root /home/foobar/commandsapp
Environment development
--
cgit v1.2.3
From 4ea21b6de260dd4cd610f88ae8d19a04977b5c2a Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sat, 22 Oct 2011 15:54:55 +0530
Subject: Updated rack version in docs for 3.2
---
railties/guides/source/command_line.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index ffa198891a..3f8643eca3 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -381,7 +381,7 @@ $ rake about
About your application's environment
Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.3.6
-Rack version 1.1
+Rack version 1.3
Rails version 3.2.0.beta
JavaScript Runtime Node.js (V8)
Active Record version 3.2.0.beta
--
cgit v1.2.3
From 227c31f7b6b13fcfc187d20618ed14d2970314c7 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 23 Oct 2011 01:34:02 +0530
Subject: edge doesnt provide turn gem in the gemfile anymore
---
railties/guides/code/getting_started/Gemfile | 5 -----
1 file changed, 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/Gemfile b/railties/guides/code/getting_started/Gemfile
index 51774934cd..898510dcaa 100644
--- a/railties/guides/code/getting_started/Gemfile
+++ b/railties/guides/code/getting_started/Gemfile
@@ -25,8 +25,3 @@ gem 'jquery-rails'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
-
-group :test do
- # Pretty printed test output
- gem 'turn', :require => false
-end
--
cgit v1.2.3
From 7c6d4377b85a4e534f627a8b6ea126d74a7bb039 Mon Sep 17 00:00:00 2001
From: Bruce Adams
Date: Mon, 24 Oct 2011 16:18:42 -0400
Subject: note that after_initialize is run for rake tasks
---
railties/guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 58b92e7f9e..bb494fbd33 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -40,7 +40,7 @@ Rails will use that particular setting to configure Active Record.
h4. Rails General Configuration
-* +config.after_initialize+ takes a block which will be ran _after_ Rails has finished initializing the application. That includes the initialization of the framework itself, plugins, engines, and all the application's initializers in +config/initializers+. Useful for configuring values set up by other initializers:
+* +config.after_initialize+ takes a block which will be run _after_ Rails has finished initializing the application. That includes the initialization of the framework itself, plugins, engines, and all the application's initializers in +config/initializers+. Note that this block _will_ be run for rake tasks. Useful for configuring values set up by other initializers:
config.after_initialize do
--
cgit v1.2.3
From 771ca79f74db1e5a19703ad92472515dbebb70c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Tue, 25 Oct 2011 22:22:43 +0200
Subject: Revert "Merge pull request #3395 from bdurand/fix_file_store_cleanup"
Tests were failing on Travis-CI.
This reverts commit 79d01a8f16e20c556a086a2f07e3ccb4400f9819, reversing
changes made to b838570bd69ff13d677fb43e79f10d6f3168c696.
---
railties/guides/source/caching_with_rails.textile | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 721c791a33..4273d0dd64 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -289,11 +289,7 @@ ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"
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.
-Note that the cache will grow until the disk is full unless you periodically clear out old entries. You can call +ActiveSupport::Cache::FileStore#cleanup+ to remove entries older than a specified time.
-
-
-Rails.cache.cleanup(:not_accessed_in => 2.days)
-
+Note that the cache will grow until the disk is full unless you periodically clear out old entries.
h4. ActiveSupport::Cache::MemCacheStore
--
cgit v1.2.3
From df5f88c7c0fce0d3b7a994ae376e626cd6d47d34 Mon Sep 17 00:00:00 2001
From: Henare Degan
Date: Wed, 26 Oct 2011 19:03:53 +1200
Subject: Fix a little typo
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 6eb4ae49e3..6ff5e87b6d 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -438,7 +438,7 @@ location ~ ^/assets/ {
}
-When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. One the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
+When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. On the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
Nginx is able to do this automatically enabling +gzip_static+:
--
cgit v1.2.3
From f936996f69ec728b7c0d38cd30084fc74943f9c7 Mon Sep 17 00:00:00 2001
From: Joost Baaij
Date: Fri, 28 Oct 2011 13:24:14 +0200
Subject: Updated links to authentication plugins.
Removed mention of restful_authentication.
Added devise and authlogic.
Also mention Rails 3.1 built-in logic.
---
railties/guides/source/security.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index a499ef3d39..c2ef7bf9b5 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -474,7 +474,7 @@ h3. User Management
-- _Almost every web application has to deal with authorization and authentication. Instead of rolling your own, it is advisable to use common plug-ins. But keep them up-to-date, too. A few additional precautions can make your application even more secure._
-There are some authorization and authentication plug-ins for Rails available. A good one saves only encrypted passwords, not plain-text passwords. The most popular plug-in is +restful_authentication+ which protects from session fixation, too. However, earlier versions allowed you to login without user name and password in certain circumstances.
+There are a number of authentication plug-ins for Rails available. Good ones, such as the popular "devise":https://github.com/plataformatec/devise and "authlogic":https://github.com/binarylogic/authlogic, store only encrypted passwords, not plain-text passwords. In Rails 3.1 you can use the built-in +has_secure_password+ method which has similar features.
Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to NULL in the database. If someone requested an URL like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator):
--
cgit v1.2.3
From 11f6795b238172c4a13176062bd38b83285799b7 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Sat, 29 Oct 2011 18:03:35 -0700
Subject: defines Module#qualified_const_(defined?|get|set) and
String#deconstantize
This commit also implements a faster version of #demodulize I was unable
to isolate with git add --patch.
Not a big fan of the name #deconstantize. It complements #demodulize
getting rid of the rightmost constant, hence the name, but it is
unrelated to the well-known #constantize. So unsure. Could not come
with anything better, please feel free to rename.
---
.../source/active_support_core_extensions.textile | 83 ++++++++++++++++++++++
1 file changed, 83 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index c04e49281e..0941953d1c 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -725,6 +725,64 @@ WARNING: This method returns precise results in Ruby 1.9. In older versions of R
NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
+h5. Qualified Constant Names
+
+The standard methods +const_defined?+, +const_get+ , and +const_set+ accept
+bare constant names. Active Support extends this API to be able to pass
+relative qualified constant reference expressions.
+
+The new methods are +qualified_const_defined?+, +qualified_const_get+, and
++qualified_const_set+. Their arguments are assumed to be qualified constant
+names relative to their receiver:
+
+
+Object.qualified_const_defined?("Math::PI") # => true
+Object.qualified_const_get("Math::PI") # => 3.141592653589793
+Object.qualified_const_set("Math::Phi", 1.618034) # => 1.618034
+
+
+Arguments may be bare constant names:
+
+
+Math.qualified_const_get("E") # => 2.718281828459045
+
+
+These methods are analogous to their builtin counterparts. In particular,
++qualified_constant_defined?+ accepts an optional second argument in 1.9
+to be able to say whether you want the predicate to look in the ancestors.
+This flag is taken into account for each constant in the expression while
+walking down the path.
+
+For example, given
+
+
+module M
+ X = 1
+end
+
+module N
+ class C
+ include M
+ end
+end
+
+
++qualified_const_defined?+ behaves this way:
+
+
+N.qualified_const_defined?("C::X", false) # => false (1.9 only)
+N.qualified_const_defined?("C::X", true) # => true (1.9 only)
+N.qualified_const_defined?("C::X") # => false in 1.8, true in 1.9
+
+
+As the last example implies, in 1.9 the second argument defaults to true,
+as in +const_defined?+.
+
+For coherence with the builtin methods only relative paths are accepted.
+Absolute qualified constant names like +::Math::PI+ raise +NameError+.
+
+NOTE: Defined in +active_support/core_ext/module/qualified_const.rb+.
+
h4. Synchronization
The +synchronize+ macro declares a method to be synchronized:
@@ -1620,6 +1678,31 @@ end
NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
+h5. +deconstantize+
+
+Given a string with a qualified constant reference expression, +deconstantize+ removes the rightmost segment, generally leaving the name of the constant's container:
+
+
+"Product".deconstantize # => ""
+"Backoffice::UsersController".deconstantize # => "Backoffice"
+"Admin::Hotel::ReservationUtils".deconstantize # => "Admin::Hotel"
+
+
+Active Support for example uses this method in +Module#qualified_const_set+:
+
+
+def qualified_const_set(path, value)
+ QualifiedConstUtils.raise_if_absolute(path)
+
+ const_name = path.demodulize
+ mod_name = path.deconstantize
+ mod = mod_name.empty? ? self : qualified_const_get(mod_name)
+ mod.const_set(const_name, value)
+end
+
+
+NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
+
h5. +parameterize+
The method +parameterize+ normalizes its receiver in a way that can be used in pretty URLs.
--
cgit v1.2.3
From c6b933faa91107a8213f0e8e151f8f1a72f55cdc Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Sun, 30 Oct 2011 02:24:30 -0700
Subject: prefer qualified constant "name" to "reference expression", much
simpler
---
railties/guides/source/active_support_core_extensions.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 0941953d1c..ff6c5f967f 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -729,7 +729,7 @@ h5. Qualified Constant Names
The standard methods +const_defined?+, +const_get+ , and +const_set+ accept
bare constant names. Active Support extends this API to be able to pass
-relative qualified constant reference expressions.
+relative qualified constant names.
The new methods are +qualified_const_defined?+, +qualified_const_get+, and
+qualified_const_set+. Their arguments are assumed to be qualified constant
@@ -1655,7 +1655,7 @@ NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
h5. +demodulize+
-Given a string with a qualified constant reference expression, +demodulize+ returns the very constant name, that is, the rightmost part of it:
+Given a string with a qualified constant name, +demodulize+ returns the very constant name, that is, the rightmost part of it:
"Product".demodulize # => "Product"
--
cgit v1.2.3
From 2d337ef080aec2c2e21ede3451f652ab5eaadca1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gon=C3=A7alo=20Silva?=
Date: Sun, 30 Oct 2011 18:34:49 -0200
Subject: Fix typo on the performance test guide
---
railties/guides/source/performance_testing.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index f3ea7e38bc..2440927542 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -447,7 +447,7 @@ h4. Using Ruby-Prof on MRI and REE
Add Ruby-Prof to your applications' Gemfile if you want to benchmark/profile under MRI or REE:
-gem 'ruby-prof', :path => 'git://github.com/wycats/ruby-prof.git'
+gem 'ruby-prof', :git => 'git://github.com/wycats/ruby-prof.git'
Now run +bundle install+ and you're ready to go.
--
cgit v1.2.3
From d106b34bd582483ebae57f8fa57f8d3649a31829 Mon Sep 17 00:00:00 2001
From: Alexey Vakhov
Date: Mon, 31 Oct 2011 10:36:38 +0400
Subject: Update routing guides, root route should be at the top of the file
---
railties/guides/source/routing.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index f281009fee..29c729592b 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -620,7 +620,7 @@ You can specify what Rails should route +"/"+ to with the +root+ method:
root :to => 'pages#main'
-You should put the +root+ route at the end of the file. You also need to delete the +public/index.html+ file for the root route to take effect.
+You should put the +root+ route at the top of the file, because it is the most popular route and should be matched first. You also need to delete the +public/index.html+ file for the root route to take effect.
h3. Customizing Resourceful Routes
--
cgit v1.2.3
From dfdbbe059f464a0ab2437a93e9f8222942920155 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 28 Oct 2011 18:46:18 +1100
Subject: [engines guide] add 'General engine configuration' section
---
railties/guides/source/engines.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile
index da56f3d0ed..694b36bea1 100644
--- a/railties/guides/source/engines.textile
+++ b/railties/guides/source/engines.textile
@@ -506,6 +506,10 @@ Now instead of the ugly Ruby object output the author's name will be displayed.
h4. Configuring an engine
+This section covers firstly how you can make the +user_class+ setting of the Blorgh engine configurable, followed by general configuration tips for the engine.
+
+h5. Setting configuration settings in the application
+
The next step is to make the class that represents a +User+ in the application customizable for the engine. This is because, as explained before, that class may not always be +User+. To make this customizable, the engine will have a configuration setting called +user_class+ that will be used to specify what the class representing users is inside the application.
To define this configuration setting, you should use a +mattr_accessor+ inside the +Blorgh+ module for the engine, located at +lib/blorgh.rb+ inside the engine. Inside this module, put this line:
@@ -542,6 +546,14 @@ Go ahead and try to create a new post. You will see that it works exactly in the
There are now no strict dependencies on what the class is, only what the class's API must be. The engine simply requires this class to define a +find_or_create_by_name+ method which returns an object of that class to be associated with a post when it's created.
+h5. General engine configuration
+
+Within an engine, there may come a time where you wish to use things such as initializers, internationalization or other configuration options. The great news is that these things are entirely possible because a Rails engine shares much the same functionality as a Rails application. In fact, a Rails application's functionality is actually a superset of what is provided by engines!
+
+If you wish to use initializers (code that should run before the engine is loaded), the best place for them is the +config/initializers+ folder. This directory's functionality is explained in the "Initializers section":http://guides.rubyonrails.org/configuring.html#initializers of the Configuring guide.
+
+For locales, simply place the locale files in the +config/locales+ directory, just like you would in an application.
+
h3. Extending engine functionality
This section looks at overriding or adding functionality to the views, controllers and models provided by an engine.
--
cgit v1.2.3
From e28bd7b22698dc2a5df05fe6ab9ceba715452a33 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 1 Nov 2011 11:18:17 +1100
Subject: [config guide] mention that config methods are to be called on
Railtie subclasses
---
railties/guides/source/configuring.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index bb494fbd33..cd6e7d116e 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -40,6 +40,8 @@ Rails will use that particular setting to configure Active Record.
h4. Rails General Configuration
+These configuration methods are to be called on a +Rails::Railtie+ object, such as a subclass of +Rails::Engine+ or +Rails::Application+.
+
* +config.after_initialize+ takes a block which will be run _after_ Rails has finished initializing the application. That includes the initialization of the framework itself, plugins, engines, and all the application's initializers in +config/initializers+. Note that this block _will_ be run for rake tasks. Useful for configuring values set up by other initializers:
--
cgit v1.2.3
From ed4bde5a0937f8eadfd806b1f579048bf5ac9b07 Mon Sep 17 00:00:00 2001
From: juandebravo
Date: Tue, 1 Nov 2011 20:45:00 +0200
Subject: Fix wrong link in initialization doc
---
railties/guides/source/initialization.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index f88405a2fd..7710c9bd6c 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -817,7 +817,7 @@ def initializer(name, opts = {}, &blk)
end
-An initializer can be configured to run before or after another initializer, which we'll see a couple of times throughout this initialization process. Anything that inherits from +Rails::Railtie+ may also make use of the +initializer+ method, something which is covered in the "Configuration guide":[http://ryanbigg.com/guides/configuring.html#rails-railtie-initializer].
+An initializer can be configured to run before or after another initializer, which we'll see a couple of times throughout this initialization process. Anything that inherits from +Rails::Railtie+ may also make use of the +initializer+ method, something which is covered in the "Configuration guide":http://guides.rubyonrails.org/configuring.html#rails-railtie-initializer.
The +Initializer+ class here is defined within the +Rails::Initializable+ module and its +initialize+ method is defined to just set up a couple of variables:
--
cgit v1.2.3
From 9aa880f2e860ff2058dc0d359c6310848b1e4383 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 2 Nov 2011 00:37:18 +0530
Subject: use relative urls for linking to sections in the guides
---
railties/guides/source/initialization.textile | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 7710c9bd6c..036b356a37 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -525,19 +525,19 @@ silence_warnings do
end
-These methods can be used to silence STDERR responses and the +silence_stream+ allows you to also silence other streams. Additionally, this mixin allows you to suppress exceptions and capture streams. For more information see the "Silencing Warnings, Streams, and Exceptions":http://guides.rubyonrails.org/active_support_core_extensions.html#silencing-warnings-streams-and-exceptions section from the Active Support Core Extensions Guide.
+These methods can be used to silence STDERR responses and the +silence_stream+ allows you to also silence other streams. Additionally, this mixin allows you to suppress exceptions and capture streams. For more information see the "Silencing Warnings, Streams, and Exceptions":active_support_core_extensions.html#silencing-warnings-streams-and-exceptions section from the Active Support Core Extensions Guide.
h4. +active_support/core_ext/logger.rb+
The next file that is required is another Active Support core extension, this time to the +Logger+ class. This begins by defining the +around_[level]+ helpers for the +Logger+ class as well as other methods such as a +datetime_format+ getter and setter for the +formatter+ object tied to a +Logger+ object.
-For more information see the "Extensions to Logger":http://guides.rubyonrails.org/active_support_core_extensions.html#extensions-to-logger section from the Active Support Core Extensions Guide.
+For more information see the "Extensions to Logger":active_support_core_extensions.html#extensions-to-logger section from the Active Support Core Extensions Guide.
h4. +railties/lib/rails/application.rb+
The next file required by +railties/lib/rails.rb+ is +application.rb+. This file defines the +Rails::Application+ constant which the application's class defined in +config/application.rb+ in a standard Rails application depends on. Before the +Rails::Application+ class is defined however, there's some other files that get required first.
-The first of these is +active_support/core_ext/hash/reverse_merge+ which can be "read about in the Active Support Core Extensions guide":http://guides.rubyonrails.org/active_support_core_extensions.html#merging under the "Merging" section.
+The first of these is +active_support/core_ext/hash/reverse_merge+ which can be "read about in the Active Support Core Extensions guide":active_support_core_extensions.html#merging under the "Merging" section.
h4. +active_support/file_update_checker.rb+
@@ -575,7 +575,7 @@ Now that +rails/initializable.rb+ has finished being required from +rails/railti
h4. +railties/lib/rails/configuration.rb+
-This file defines the +Rails::Configuration+ module, containing the +MiddlewareStackProxy+ class as well as the +Generators+ class. The +MiddlewareStackProxy+ class is used for managing the middleware stack for an application, which we'll see later on. The +Generators+ class provides the functionality used for configuring what generators an application uses through the "+config.generators+ option":http://guides.rubyonrails.org/configuring.html#configuring-generators.
+This file defines the +Rails::Configuration+ module, containing the +MiddlewareStackProxy+ class as well as the +Generators+ class. The +MiddlewareStackProxy+ class is used for managing the middleware stack for an application, which we'll see later on. The +Generators+ class provides the functionality used for configuring what generators an application uses through the "+config.generators+ option":configuring.html#configuring-generators.
The first file required in this file is +activesupport/deprecation+.
@@ -598,11 +598,11 @@ This file defines the +ActiveSupport::Notifications+ module. Notifications provi
The "API documentation":http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html for +ActiveSupport::Notifications+ explains the usage of this module, including the methods that it defines.
-The file required in +active_support/notifications.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation.
+The file required in +active_support/notifications.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":active_support_core_extensions.html#method-delegation.
h4. +activesupport/core_ext/array/wrap+
-As this file comprises of a core extension, it is covered exclusively in "the Active Support Core Extensions guide":http://guides.rubyonrails.org/active_support_core_extensions.html#wrapping
+As this file comprises of a core extension, it is covered exclusively in "the Active Support Core Extensions guide":active_support_core_extensions.html#wrapping
h4. +activesupport/lib/active_support/deprecation/reporting.rb+
@@ -624,7 +624,7 @@ h4. +active_support/ordered_options+
This file is the next file required from +rails/configuration.rb+ is the file that defines +ActiveSupport::OrderedOptions+ which is used for configuration options such as +config.active_support+ and the like.
-The next file required is +active_support/core_ext/hash/deep_dup+ which is covered in "Active Support Core Extensions guide":http://guides.rubyonrails.org/active_support_core_extensions.html#deep_dup
+The next file required is +active_support/core_ext/hash/deep_dup+ which is covered in "Active Support Core Extensions guide":active_support_core_extensions.html#deep_dup
The file that is required next from is +rails/paths+
@@ -682,7 +682,7 @@ When the module from this file (+Rails::Initializable+) is included, it extends
h4. +railties/lib/rails/engine.rb+
-The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":http://guides.rubyonrails.org/active_support_core_extensions.html#method-delegation.
+The next file required in +rails/engine.rb+ is +active_support/core_ext/module/delegation+ which is documented in the "Active Support Core Extensions Guide":active_support_core_extensions.html#method-delegation.
The next two files after this are Ruby standard library files: +pathname+ and +rbconfig+. The file after these is +rails/engine/railties+.
@@ -698,7 +698,7 @@ Once this file has finished loading we jump back to +railties/lib/rails/plugin.r
h4. Back to +railties/lib/rails/plugin.rb+
-The next file required in this is a core extension from Active Support called +array/conversions+ which is covered in "this section":http://guides.rubyonrails.org/active_support_core_extensions.html#array-conversions of the Active Support Core Extensions Guide.
+The next file required in this is a core extension from Active Support called +array/conversions+ which is covered in "this section":active_support_core_extensions.html#array-conversions of the Active Support Core Extensions Guide.
Once that file has finished loading, the +Rails::Plugin+ class is defined.
@@ -817,7 +817,7 @@ def initializer(name, opts = {}, &blk)
end
-An initializer can be configured to run before or after another initializer, which we'll see a couple of times throughout this initialization process. Anything that inherits from +Rails::Railtie+ may also make use of the +initializer+ method, something which is covered in the "Configuration guide":http://guides.rubyonrails.org/configuring.html#rails-railtie-initializer.
+An initializer can be configured to run before or after another initializer, which we'll see a couple of times throughout this initialization process. Anything that inherits from +Rails::Railtie+ may also make use of the +initializer+ method, something which is covered in the "Configuration guide":configuring.html#rails-railtie-initializer.
The +Initializer+ class here is defined within the +Rails::Initializable+ module and its +initialize+ method is defined to just set up a couple of variables:
--
cgit v1.2.3
From b3c1cfa2772e64b20681bae8e765f37660087b18 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 2 Nov 2011 23:01:30 +0530
Subject: minor edits in AR validations guide
---
.../source/active_record_validations_callbacks.textile | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 665e7f9ccc..4c1f66aedf 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -796,17 +796,9 @@ person.errors.size # => 0
h3. Displaying Validation Errors in the View
-Rails maintains an official plugin, DynamicForm, that provides helpers to display the error messages of your models in your view templates. You can install it as a plugin or as a Gem.
+"DynamicForm":https://github.com/joelmoss/dynamic_form provides helpers to display the error messages of your models in your view templates.
-h4. Installing as a plugin
-
-
-$ rails plugin install git://github.com/joelmoss/dynamic_form.git
-
-
-h4. Installing as a Gem
-
-Add this line in your Gemfile:
+You can install it as a gem by adding this line to your Gemfile:
gem "dynamic_form"
--
cgit v1.2.3
From bc09a11a666a1fba848d866dd61bf7123d4d5759 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 2 Nov 2011 23:34:27 +0530
Subject: minor edit
---
railties/guides/source/action_view_overview.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index 40cde6ad84..e2b69fa0d5 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -16,7 +16,7 @@ Action View and Action Controller are the two major components of Action Pack. I
Action View templates are written using embedded Ruby in tags mingled with HTML. To avoid cluttering the templates with boilerplate code, a number of helper classes provide common behavior for forms, dates, and strings. It's also easy to add new helpers to your application as it evolves.
-Note: Some features of Action View are tied to Active Record, but that doesn't mean that Action View depends on Active Record. Action View is an independent package that can be used with any sort of backend.
+NOTE. Some features of Action View are tied to Active Record, but that doesn't mean that Action View depends on Active Record. Action View is an independent package that can be used with any sort of backend.
h3. Using Action View with Rails
--
cgit v1.2.3
From 8611f14cafea0e2fcfddd9d22cca442c31664940 Mon Sep 17 00:00:00 2001
From: Henrik Hodne
Date: Thu, 3 Nov 2011 22:19:49 +0100
Subject: Added bundle exec to rake test.
This is in response to rails/rails#3504.
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 5848172510..4d84c50e2a 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -87,21 +87,21 @@ $ bundle install --without db
This command will install all dependencies except the MySQL and PostgreSQL Ruby drivers. We will come back at these soon. With dependencies installed, you can run the test suite with:
-$ rake test
+$ bundle exec rake test
You can also run tests for a specific framework, like Action Pack, by going into its directory and executing the same command:
$ cd actionpack
-$ rake test
+$ bundle exec rake test
If you want to run tests from the specific directory use the +TEST_DIR+ environment variable. For example, this will run tests inside +railties/test/generators+ directory only:
$ cd railties
-$ TEST_DIR=generators rake test
+$ TEST_DIR=generators bundle exec rake test
h4. Warnings
@@ -111,7 +111,7 @@ The test suite runs with warnings enabled. Ideally Ruby on Rails should issue no
As of this writing they are specially noisy with Ruby 1.9. If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag:
-$ RUBYOPT=-W0 rake test
+$ RUBYOPT=-W0 bundle exec rake test
h4. Testing Active Record
@@ -130,7 +130,7 @@ The gem +sqlite3-ruby+ does not belong to the "db" group indeed, if you followed
$ cd activerecord
-$ rake test_sqlite3
+$ bundle exec rake test_sqlite3
h5. MySQL and PostgreSQL
@@ -195,7 +195,7 @@ test_postgresql
respectively. As we mentioned before
-$ rake test
+$ bundle exec rake test
will now run the four of them in turn.
--
cgit v1.2.3
From bcd25e7576094a98dbc9f4b1ba2fb3451d13bf40 Mon Sep 17 00:00:00 2001
From: Florian Walch
Date: Sat, 5 Nov 2011 13:34:01 +0100
Subject: Fixed after_initialize/after_find guide
Defining after_initialize and after_find as ordinary methods like documented
in the guide doesn't work with Rails 3.1.1; now macro-style is used here, too.
---
railties/guides/source/active_record_validations_callbacks.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 4c1f66aedf..a27c292a4c 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -978,15 +978,15 @@ The +after_initialize+ callback will be called whenever an Active Record object
The +after_find+ callback will be called whenever Active Record loads a record from the database. +after_find+ is called before +after_initialize+ if both are defined.
-The +after_initialize+ and +after_find+ callbacks are a bit different from the others. They have no +before_*+ counterparts, and they are registered simply by defining them as regular methods with predefined names. If you try to register +after_initialize+ or +after_find+ using macro-style class methods, they will just be ignored. This behavior is due to performance reasons, since +after_initialize+ and +after_find+ will both be called for each record found in the database, which would otherwise significantly slow down the queries.
+The +after_initialize+ and +after_find+ callbacks have no +before_*+ counterparts, but they can be registered just like the other Active Record callbacks.
class User < ActiveRecord::Base
- def after_initialize
+ after_initialize do |user|
puts "You have initialized an object!"
end
- def after_find
+ after_find do |user|
puts "You have found an object!"
end
end
--
cgit v1.2.3
From 562583c7667f508493ab8c5b1a4215087fafd22d Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 4 Nov 2011 16:10:18 +0000
Subject: Add ActiveRecord::Relation#uniq for toggling DISTINCT in the SQL
query
---
.../guides/source/active_record_querying.textile | 24 ++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 2e1f89cb78..0ad2644095 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -201,7 +201,7 @@ end
But this approach becomes increasingly impractical as the table size increases, since +User.all.each+ instructs Active Record to fetch _the entire table_ in a single pass, build a model object per row, and then keep the entire array of model objects in memory. Indeed, if we have a large number of records, the entire collection may exceed the amount of memory available.
-Rails provides two methods that address this problem by dividing records into memory-friendly batches for processing. The first method, +find_each+, retrieves a batch of records and then yields _each_ record to the block individually as a model. The second method, +find_in_batches+, retrieves a batch of records and then yields _the entire batch_ to the block as an array of models.
+Rails provides two methods that address this problem by dividing records into memory-friendly batches for processing. The first method, +find_each+, retrieves a batch of records and then yields _each_ record to the block individually as a model. The second method, +find_in_batches+, retrieves a batch of records and then yields _the entire batch_ to the block as an array of models.
TIP: The +find_each+ and +find_in_batches+ methods are intended for use in the batch processing of a large number of records that wouldn't fit in memory all at once. If you just need to loop over a thousand records the regular find methods are the preferred option.
@@ -435,10 +435,26 @@ ActiveModel::MissingAttributeError: missing attribute:
Where +<attribute>+ is the attribute you asked for. The +id+ method will not raise the +ActiveRecord::MissingAttributeError+, so just be careful when working with associations because they need the +id+ method to function properly.
-You can also call SQL functions within the select option. For example, if you would like to only grab a single record per unique value in a certain field by using the +DISTINCT+ function you can do it like this:
+If you would like to only grab a single record per unique value in a certain field, you can use +uniq+:
-Client.select("DISTINCT(name)")
+Client.select(:name).uniq
+
+
+This would generate SQL like:
+
+
+SELECT DISTINCT name FROM clients
+
+
+You can also remove the uniqueness constraint:
+
+
+query = Client.select(:name).uniq
+# => Returns unique names
+
+query.uniq(false)
+# => Returns all names, even if there are duplicates
h3. Limit and Offset
@@ -741,7 +757,7 @@ SELECT categories.* FROM categories
INNER JOIN posts ON posts.category_id = categories.id
-Or, in English: "return a Category object for all categories with posts". Note that you will see duplicate categories if more than one post has the same category. If you want unique categories, you can use Category.joins(:post).select("distinct(categories.id)").
+Or, in English: "return a Category object for all categories with posts". Note that you will see duplicate categories if more than one post has the same category. If you want unique categories, you can use Category.joins(:post).select("distinct(categories.id)").
h5. Joining Multiple Associations
--
cgit v1.2.3
From e7b7b4412380e7ce2d8e6ae402cb7fe02d7666b8 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Tue, 20 Sep 2011 10:50:08 -0700
Subject: implements AR::Relation#explain
This is a first implementation, EXPLAIN is highly
dependent on the database and I have made some
compromises.
On one hand, the method allows you to run the most
common EXPLAIN and that's it. If you want EXPLAIN
ANALYZE in PostgreSQL you need to do it by hand.
On the other hand, I've tried to construct a string
as close as possible to the ones built by the
respective shells. The rationale is that IMO the
user should feel at home with the output and
recognize it at first sight. Per database.
I don't know whether this implementation is going
to work well. Let's see whether people like it.
---
.../guides/source/active_record_querying.textile | 65 ++++++++++++++++++++++
1 file changed, 65 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 0ad2644095..a132d85ef9 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -8,6 +8,7 @@ This guide covers different ways to retrieve data from the database using Active
* Use dynamic finders methods
* Check for the existence of particular records
* Perform various calculations on Active Record models
+* Run EXPLAIN on relations
endprologue.
@@ -1274,3 +1275,67 @@ Client.sum("orders_count")
For options, please see the parent section, "Calculations":#calculations.
+
+h3. Running EXPLAIN
+
+You can run EXPLAIN on the queries triggered by relations. For example,
+
+
+User.where(:id => 1).joins(:posts).explain
+
+
+may yield
+
+
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
+| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
+| 1 | SIMPLE | posts | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
+2 rows in set (0.00 sec)
+
+
+under MySQL.
+
+Active Record performs a pretty printing that emulates the one of the database
+shells. So, the same query running with the PostreSQL adapter would yield instead
+
+
+ QUERY PLAN
+------------------------------------------------------------------------------
+ Nested Loop Left Join (cost=0.00..37.24 rows=8 width=0)
+ Join Filter: (posts.user_id = users.id)
+ -> Index Scan using users_pkey on users (cost=0.00..8.27 rows=1 width=4)
+ Index Cond: (id = 1)
+ -> Seq Scan on posts (cost=0.00..28.88 rows=8 width=4)
+ Filter: (posts.user_id = 1)
+(6 rows)
+
+
+Eager loading may trigger more than one query under the hood, and some queries
+may need the results of previous ones. Because of that, +explain+ actually
+executes the query, and then asks for the query plans. For example,
+
+
+User.where(:id => 1).includes(:posts).explain
+
+
+yields
+
+
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
+| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
+1 row in set (0.00 sec)
++----+-------------+-------+------+---------------+------+---------+------+------+-------------
+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
++----+-------------+-------+------+---------------+------+---------+------+------+-------------
+| 1 | SIMPLE | posts | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
++----+-------------+-------+------+---------------+------+---------+------+------+-------------
+1 row in set (0.00 sec)
+
+
+under MySQL.
--
cgit v1.2.3
From 8750c9a1cfb055fb45a798fee952953b6db829ad Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 6 Nov 2011 18:58:55 +0530
Subject: fix markups for plus in AR guide
---
.../guides/source/active_record_querying.textile | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index a132d85ef9..8526d8511b 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1287,19 +1287,19 @@ User.where(:id => 1).joins(:posts).explain
may yield
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
+------------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
+------------------------------------------------------------------------------------------
| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
| 1 | SIMPLE | posts | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
+------------------------------------------------------------------------------------------
2 rows in set (0.00 sec)
under MySQL.
Active Record performs a pretty printing that emulates the one of the database
-shells. So, the same query running with the PostreSQL adapter would yield instead
+shells. So, the same query running with the PostgreSQL adapter would yield instead
QUERY PLAN
@@ -1324,17 +1324,17 @@ User.where(:id => 1).includes(:posts).explain
yields
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
+------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
+------------------------------------------------------------------------------------
| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
+------------------------------------------------------------------------------------
1 row in set (0.00 sec)
-+----+-------------+-------+------+---------------+------+---------+------+------+-------------
+-------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-+----+-------------+-------+------+---------------+------+---------+------+------+-------------
+-------------------------------------------------------------------------------------
| 1 | SIMPLE | posts | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
-+----+-------------+-------+------+---------------+------+---------+------+------+-------------
+-------------------------------------------------------------------------------------
1 row in set (0.00 sec)
--
cgit v1.2.3
From 17ecdd388c70f7faf002ef21be6a674b4c0df7ca Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Mon, 7 Nov 2011 02:01:37 -0800
Subject: adds trailing +s to the output of EXPLAIN for MySQL
---
railties/guides/source/active_record_querying.textile | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index a132d85ef9..ad623ae434 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1324,17 +1324,17 @@ User.where(:id => 1).includes(:posts).explain
yields
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
-+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------
++----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
1 row in set (0.00 sec)
-+----+-------------+-------+------+---------------+------+---------+------+------+-------------
++----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-+----+-------------+-------+------+---------------+------+---------+------+------+-------------
++----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | posts | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
-+----+-------------+-------+------+---------------+------+---------+------+------+-------------
++----+-------------+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
--
cgit v1.2.3
From 1ffd5ec91069167043c8ecd0d949098f566d88eb Mon Sep 17 00:00:00 2001
From: Joost Baaij
Date: Tue, 8 Nov 2011 16:27:15 +0100
Subject: Replace example with SQL placeholder syntax. This works just fine, is
less code, and reduces the risk of someone implementing a SQL injection
vulnerability.
---
railties/guides/source/association_basics.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 6829eb8ef4..451653655f 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -1234,7 +1234,7 @@ If you need to evaluate conditions dynamically at runtime, use a proc:
class Customer < ActiveRecord::Base
has_many :latest_orders, :class_name => "Order",
- :conditions => proc { "orders.created_at > #{10.hours.ago.to_s(:db).inspect}" }
+ :conditions => proc { ["orders.created_at > ?, 10.hours.ago] }
end
--
cgit v1.2.3
From f686d9429fc964ca7ef0c7a8246ac25fd861a05b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 26 Oct 2011 09:40:49 +0200
Subject: Use head :no_content on the guides as well.
---
.../guides/code/getting_started/app/controllers/posts_controller.rb | 4 ++--
railties/guides/source/getting_started.textile | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/app/controllers/posts_controller.rb b/railties/guides/code/getting_started/app/controllers/posts_controller.rb
index 7e903c984c..1581d4eb16 100644
--- a/railties/guides/code/getting_started/app/controllers/posts_controller.rb
+++ b/railties/guides/code/getting_started/app/controllers/posts_controller.rb
@@ -62,7 +62,7 @@ class PostsController < ApplicationController
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
- format.json { head :ok }
+ format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @post.errors, status: :unprocessable_entity }
@@ -78,7 +78,7 @@ class PostsController < ApplicationController
respond_to do |format|
format.html { redirect_to posts_url }
- format.json { head :ok }
+ format.json { head :no_content }
end
end
end
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index bf6104b96b..ef80086eff 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1060,7 +1060,7 @@ def update
if @post.update_attributes(params[:post])
format.html { redirect_to(@post,
:notice => 'Post was successfully updated.') }
- format.json { render :json => {}, :status => :ok }
+ format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @post.errors,
@@ -1089,7 +1089,7 @@ def destroy
respond_to do |format|
format.html { redirect_to posts_url }
- format.json { head :ok }
+ format.json { head :no_content }
end
end
--
cgit v1.2.3
From 74233d48e64650c26600f82ac23eb55c39fea342 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 10 Nov 2011 22:36:20 +0530
Subject: Fixes deprecation warning about passing a template handler in the
template name while generating guide related pages like index, layout and
credits
---
railties/guides/rails_guides/generator.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb
index 4682ead66e..6f6d3bda80 100644
--- a/railties/guides/rails_guides/generator.rb
+++ b/railties/guides/rails_guides/generator.rb
@@ -137,7 +137,8 @@ module RailsGuides
if guide =~ /\.html\.erb$/
# Generate the special pages like the home.
- result = view.render(:layout => 'layout', :file => guide)
+ # Passing a template handler in the template name is deprecated. So pass the file name without the extension.
+ result = view.render(:layout => 'layout', :file => $`)
else
body = File.read(File.join(source_dir, guide))
body = set_header_section(body, view)
--
cgit v1.2.3
From b9aaa317cfa56a68b406181a93d9e11b8560f9a1 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 11 Nov 2011 01:49:05 +0530
Subject: update ci file name in contributing guide
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 4d84c50e2a..80c3cf6e1a 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -200,7 +200,7 @@ $ bundle exec rake test
will now run the four of them in turn.
-You can also invoke +test_jdbcmysql+, +test_jdbcsqlite3+ or +test_jdbcpostgresql+. Check out the file +activerecord/RUNNING_UNIT_TESTS+ for information on running more targeted database tests, or the file +ci/ci_build.rb+ to see the test suite that the continuous integration server runs.
+You can also invoke +test_jdbcmysql+, +test_jdbcsqlite3+ or +test_jdbcpostgresql+. Check out the file +activerecord/RUNNING_UNIT_TESTS+ for information on running more targeted database tests, or the file +ci/travis.rb+ to see the test suite that the continuous integration server runs.
h4. Older versions of Ruby on Rails
--
cgit v1.2.3
From 84908fa38264ea6de55fb7a858b4af7b64bb6efa Mon Sep 17 00:00:00 2001
From: Prem Sichanugrist
Date: Fri, 11 Nov 2011 13:34:55 -0500
Subject: For what it's worth; Update `memcache-client` gem name
---
railties/guides/source/caching_with_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 4273d0dd64..5bf2284230 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -293,7 +293,7 @@ Note that the cache will grow until the disk is full unless you periodically cle
h4. ActiveSupport::Cache::MemCacheStore
-This cache store uses Danga's +memcached+ server to provide a centralized cache for your application. Rails uses the bundled +memcached-client+ gem by default. This is currently the most popular cache store for production websites. It can be used to provide a single, shared cache cluster with very a high performance and redundancy.
+This cache store uses Danga's +memcached+ server to provide a centralized cache for your application. Rails uses the bundled +memcache-client+ gem by default. This is currently the most popular cache store for production websites. It can be used to provide a single, shared cache cluster with very a high performance and redundancy.
When initializing the cache, you need to specify the addresses for all memcached servers in your cluster. If none is specified, it will assume memcached is running on the local host on the default port, but this is not an ideal set up for larger sites.
--
cgit v1.2.3
From 650ec898e5f4668b63925d05f8b722a5226a79dd Mon Sep 17 00:00:00 2001
From: Cheah Chu Yeow
Date: Sun, 13 Nov 2011 13:25:39 +0800
Subject: Suggest a workaround for page caching and parameters instead of an
unhelpful warning.
---
railties/guides/source/caching_with_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 5bf2284230..972579b453 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -64,7 +64,7 @@ end
If you want a more complicated expiration scheme, you can use cache sweepers to expire cached objects when things change. This is covered in the section on Sweepers.
-NOTE: Page caching ignores all parameters. For example +/products?page=1+ will be written out to the filesystem as +products.html+ with no reference to the +page+ parameter. Thus, if someone requests +/products?page=2+ later, they will get the cached first page. Be careful when page caching GET parameters in the URL!
+NOTE: Page caching ignores all parameters. For example +/products?page=1+ will be written out to the filesystem as +products.html+ with no reference to the +page+ parameter. Thus, if someone requests +/products?page=2+ later, they will get the cached first page. A workaround for this limitation is to include the parameters in the page's path, e.g. +/productions/page/1+.
INFO: Page caching runs in an after filter. Thus, invalid requests won't generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job.
--
cgit v1.2.3
From d9703fe92ea0d39eed7bec44027468e6fed70a8a Mon Sep 17 00:00:00 2001
From: Cheah Chu Yeow
Date: Sun, 13 Nov 2011 13:34:16 +0800
Subject: Clearing cache in action caching is not "the exact same way" as with
page caching.
---
railties/guides/source/caching_with_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 972579b453..aa08148bdb 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -72,7 +72,7 @@ h4. Action Caching
One of the issues with Page Caching is that you cannot use it for pages that require to restrict access somehow. This is where Action Caching comes in. Action Caching works like Page Caching except for the fact that the incoming web request does go from the webserver to the Rails stack and Action Pack so that before filters can be run on it before the cache is served. This allows authentication and other restriction to be run while still serving the result of the output from a cached copy.
-Clearing the cache works in the exact same way as with Page Caching.
+Clearing the cache works in a similar way to Page Caching, except you use the +expire_action+ instead of +expire_page+.
Let's say you only wanted authenticated users to call actions on +ProductsController+.
--
cgit v1.2.3
From f323b425f29b633e07441cbc97fcbecf7e4b61a8 Mon Sep 17 00:00:00 2001
From: Cheah Chu Yeow
Date: Sun, 13 Nov 2011 13:35:32 +0800
Subject: Fix bad English.
---
railties/guides/source/caching_with_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index aa08148bdb..0ef6f51190 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -72,7 +72,7 @@ h4. Action Caching
One of the issues with Page Caching is that you cannot use it for pages that require to restrict access somehow. This is where Action Caching comes in. Action Caching works like Page Caching except for the fact that the incoming web request does go from the webserver to the Rails stack and Action Pack so that before filters can be run on it before the cache is served. This allows authentication and other restriction to be run while still serving the result of the output from a cached copy.
-Clearing the cache works in a similar way to Page Caching, except you use the +expire_action+ instead of +expire_page+.
+Clearing the cache works in a similar way to Page Caching, except you use +expire_action+ instead of +expire_page+.
Let's say you only wanted authenticated users to call actions on +ProductsController+.
--
cgit v1.2.3
From 962c55de0d24561d54babe5608630f93afc2681f Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:16:58 -0700
Subject: Add Tip about skipping to Section 3 if they want to come back to the
philosophy later
---
railties/guides/source/getting_started.textile | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index bf6104b96b..ce556a0f87 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -46,6 +46,10 @@ in rails/railties/guides/code/getting_started.
h3. What is Rails?
+TIP: This section goes into the background and philosophy of the Rails framework
+in detail. You can safely skip this section and come back to it at a later time.
+Section 3 starts you on the path to creating your first Rails application.
+
Rails is a web application development framework written in the Ruby language.
It is designed to make programming web applications easier by making assumptions
about what every developer needs to get started. It allows you to write less
--
cgit v1.2.3
From ee100128c3a917f96d6f40293bb5a5ed3bcf8c27 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:18:24 -0700
Subject: Move paragraphs to flow better
- Give the user a way to know they are fully installed and ready to continue
---
railties/guides/source/getting_started.textile | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index ce556a0f87..447b8e86d0 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -219,7 +219,12 @@ Ian Robinson
h3. Creating a New Rails Project
-If you follow this guide, you'll create a Rails project called blog, a
+The best way to use this guide is to follow each step as it happens, no code or
+step needed to make this example application has been left out, so you can
+literally follow along step by step. If you need to see the completed code, you
+can download it from "Getting Started Code":https://github.com/mikel/getting-started-code.
+
+By following along with this guide, you'll create a Rails project called blog, a
(very) simple weblog. Before you can start building the application, you need to
make sure that you have Rails itself installed.
@@ -237,13 +242,16 @@ Usually run this as the root user:
TIP. If you're working on Windows, you can quickly install Ruby and Rails with
"Rails Installer":http://railsinstaller.org.
-h4. Creating the Blog Application
+To verify that you have everything installed correctly, you should be able to run
+the following:
-The best way to use this guide is to follow each step as it happens, no code or
-step needed to make this example application has been left out, so you can
-literally follow along step by step. If you need to see the completed code, you
-can download it from "Getting Started
-Code":https://github.com/mikel/getting-started-code.
+
+# rails --version
+
+
+If it says something like "Rails 3.1.1" you are ready to continue.
+
+h4. Creating the Blog Application
To begin, open a terminal, navigate to a folder where you have rights to create
files, and type:
--
cgit v1.2.3
From 6ac65c92029d3eefd101f9458d86bae0314cd14c Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:19:21 -0700
Subject: Use rails help new instead of rails new -h
---
railties/guides/source/getting_started.textile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 447b8e86d0..b9a0f6a8ba 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -263,8 +263,7 @@ $ rails new blog
This will create a Rails application called Blog in a directory called blog.
TIP: You can see all of the switches that the Rails application builder accepts
-by running
-rails new -h.
+by running rails help new.
After you create the blog application, switch to its folder to continue work
directly in that application:
--
cgit v1.2.3
From b778a7eefbf755f5f131b5af06a4c555628075a9 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:21:40 -0700
Subject: Updated wording on what 'rails new blog' did for the user
- Alphabetized the files/folders created
- Added link to Configuring Rails Applications
---
railties/guides/source/getting_started.textile | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index b9a0f6a8ba..dfd27459b4 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -272,28 +272,28 @@ directly in that application:
$ cd blog
-In any case, Rails will create a folder in your working directory called
-blog. Open up that folder and explore its contents. Most of the work in
+The 'rails new blog' command we ran above created a folder in your working directory
+called blog. The blog folder has a number of auto-generated folders
+that make up the structure of a Rails application. Most of the work in
this tutorial will happen in the app/ folder, but here's a basic
-rundown on the function of each folder that Rails creates in a new application
-by default:
+rundown on the function of each of the files and folders that Rails created by default:
|_.File/Folder|_.Purpose|
-|Gemfile|This file allows you to specify what gem dependencies are needed for your Rails application. See section on Bundler, below.|
-|README|This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.|
-|Rakefile|This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.|
|app/|Contains the controllers, models, views and assets for your application. You'll focus on this folder for the remainder of this guide.|
-|config/|Configure your application's runtime rules, routes, database, and more.|
+|config/|Configure your application's runtime rules, routes, database, and more. This is covered in more detail in "Configuring Rails Applications":configuring.html|
|config.ru|Rack configuration for Rack based servers used to start the application.|
-|db/|Shows your current database schema, as well as the database migrations. You'll learn about migrations shortly.|
+|db/|Contains your current database schema, as well as the database migrations.|
|doc/|In-depth documentation for your application.|
-|lib/|Extended modules for your application (not covered in this guide).|
+|Gemfile Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application.|
+|lib/|Extended modules for your application.|
|log/|Application log files.|
|public/|The only folder seen to the world as-is. Contains the static files and compiled assets.|
+|Rakefile|This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.|
+|README|This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.|
|script/|Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.|
|test/|Unit tests, fixtures, and other test apparatus. These are covered in "Testing Rails Applications":testing.html|
|tmp/|Temporary files|
-|vendor/|A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality.|
+|vendor/|A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you optionally install it into your project) and plugins containing additional prepackaged functionality.|
h4. Configuring a Database
--
cgit v1.2.3
From 194a42e7aa7d1812257b14eabdd30c35f45bc8ed Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:24:44 -0700
Subject: Updated wording to read better
---
railties/guides/source/getting_started.textile | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index dfd27459b4..86fcb226d5 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -300,11 +300,12 @@ h4. Configuring a Database
Just about every Rails application will interact with a database. The database
to use is specified in a configuration file, +config/database.yml+. If you open
this file in a new Rails application, you'll see a default database
-configuration using SQLite3. The file contains sections for three different
+configured to use SQLite3. The file contains sections for three different
environments in which Rails can run by default:
-* The +development+ environment is used on your development computer as you interact manually with the application.
-* The +test+ environment is used to run automated tests.
+* The +development+ environment is used on your development/local computer as you interact
+manually with the application.
+* The +test+ environment is used when running automated tests.
* The +production+ environment is used when you deploy your application for the world to use.
h5. Configuring an SQLite3 Database
--
cgit v1.2.3
From 4bf057b8661754948681a18cf17ff5676518d774 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:25:45 -0700
Subject: Move Tip up higher so users who are fine with SQLite can skip to the
next section
---
railties/guides/source/getting_started.textile | 34 ++++++++++++++------------
1 file changed, 18 insertions(+), 16 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 86fcb226d5..63afc5898f 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -334,7 +334,17 @@ and PostgreSQL "out of the box", and has plugins for many database systems. If
you are using a database in a production environment Rails most likely has an
adapter for it.
-h5. Configuring a MySQL Database
+h5. Other database configuration options
+
+TIP: You don't have to update the database configurations manually. If you look at the
+options of the application generator, you will see that one of the options
+is named --database. This option allows you to choose an adapter from a
+list of the most used relational databases. You can even run the generator
+repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting
+ of the +config/database.yml+ file, your application will be configured for MySQL
+instead of SQLite.
+
+h6. Configuring a MySQL Database
If you choose to use MySQL instead of the shipped SQLite3 database, your
+config/database.yml+ will look a little different. Here's the development
@@ -355,7 +365,7 @@ If your development computer's MySQL installation includes a root user with an
empty password, this configuration should work for you. Otherwise, change the
username and password in the +development+ section as appropriate.
-h5. Configuring a PostgreSQL Database
+h6. Configuring a PostgreSQL Database
If you choose to use PostgreSQL, your +config/database.yml+ will be customized
to use PostgreSQL databases:
@@ -370,9 +380,9 @@ development:
password:
-h5. Configuring an SQLite3 Database for JRuby Platform
+h6. Configuring an SQLite3 Database for JRuby Platform
-If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will
+If you choose to use SQLite3 and using JRuby, your +config/database.yml+ will
look a little different. Here's the development section:
@@ -381,9 +391,9 @@ development:
database: db/development.sqlite3
-h5. Configuring a MySQL Database for JRuby Platform
+h6. Configuring a MySQL Database for JRuby Platform
-If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look
+If you choose to use MySQL and using JRuby, your +config/database.yml+ will look
a little different. Here's the development section:
@@ -394,9 +404,9 @@ development:
password:
-h5. Configuring a PostgreSQL Database for JRuby Platform
+h6. Configuring a PostgreSQL Database for JRuby Platform
-Finally if you choose to use PostgreSQL and are using JRuby, your
+Finally if you choose to use PostgreSQL and using JRuby, your
+config/database.yml+ will look a little different. Here's the development
section:
@@ -411,14 +421,6 @@ development:
Change the username and password in the +development+ section as appropriate.
-TIP: You don't have to update the database configurations manually. If you look at the
-options of the application generator, you will see that one of the options
-is named --database. This option allows you to choose an adapter from a
-list of the most used relational databases. You can even run the generator
-repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting
- of the +config/database.yml+ file, your application will be configured for MySQL
-instead of SQLite.
-
h4. Creating the Database
Now that you have your database configured, it's time to have Rails create an
--
cgit v1.2.3
From 703d5c2033665987c2fa6eff9f39095fb6c03061 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:26:23 -0700
Subject: Fix typo
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 63afc5898f..c40c21102c 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -494,7 +494,7 @@ Open this file in your text editor and edit it to contain a single line of code:
h4. Setting the Application Home Page
Now that we have made the controller and view, we need to tell Rails when we
-want "Hello Rails" to show up. In our case, we want it to show up when we
+want "Hello Rails!" to show up. In our case, we want it to show up when we
navigate to the root URL of our site,
"http://localhost:3000":http://localhost:3000, instead of the "Welcome Aboard"
smoke test.
--
cgit v1.2.3
From 434fbe454cb2367e74b757ba34b7035f7379ac8a Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:27:14 -0700
Subject: Update wording to flow better
---
railties/guides/source/getting_started.textile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index c40c21102c..78cf01cdc0 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -515,8 +515,8 @@ file_ which holds entries in a special DSL (domain-specific language) that tells
Rails how to connect incoming requests to controllers and actions. This file
contains many sample routes on commented lines, and one of them actually shows
you how to connect the root of your site to a specific controller and action.
-Find the line beginning with +root :to+, uncomment it and change it like the
-following:
+Find the line beginning with +root :to+, uncomment it by removing the pound sign
+at the beginning of the line. It should look something like the following:
Blog::Application.routes.draw do
@@ -544,7 +544,7 @@ resource in a single operation, scaffolding is the tool for the job.
h3. Creating a Resource
-In the case of the blog application, you can start by generating a scaffolded
+In the case of the blog application, you can start by generating a scaffold for the
Post resource: this will represent a single blog posting. To do this, enter this
command in your terminal:
--
cgit v1.2.3
From 094bb8e50c839be9f5ed93282ececeb4e3a15d76 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:28:09 -0700
Subject: Update order so they show up in the order they do in the scaffolding
output
---
railties/guides/source/getting_started.textile | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 78cf01cdc0..d8e55eed60 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -558,21 +558,21 @@ folders, and edit config/routes.rb. Here's a quick overview of what it
|_.File |_.Purpose|
|db/migrate/20100207214725_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp)|
|app/models/post.rb |The Post model|
-|test/fixtures/posts.yml |Dummy posts for use in testing|
+|test/unit/post_test.rb |Unit testing harness for the posts model|
+|test/fixtures/posts.yml |Sample posts for use in testing|
+|config/routes.rb |Edited to include routing information for posts|
|app/controllers/posts_controller.rb |The Posts controller|
|app/views/posts/index.html.erb |A view to display an index of all posts |
|app/views/posts/edit.html.erb |A view to edit an existing post|
|app/views/posts/show.html.erb |A view to display a single post|
|app/views/posts/new.html.erb |A view to create a new post|
|app/views/posts/_form.html.erb |A partial to control the overall look and feel of the form used in edit and new views|
-|app/helpers/posts_helper.rb |Helper functions to be used from the post views|
-|app/assets/stylesheets/scaffolds.css.scss |Cascading style sheet to make the scaffolded views look better|
-|app/assets/stylesheets/posts.css.scss |Cascading style sheet for the posts controller|
-|app/assets/javascripts/posts.js.coffee |CoffeeScript for the posts controller|
-|test/unit/post_test.rb |Unit testing harness for the posts model|
|test/functional/posts_controller_test.rb |Functional testing harness for the posts controller|
+|app/helpers/posts_helper.rb |Helper functions to be used from the post views|
|test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper|
-|config/routes.rb |Edited to include routing information for posts|
+|app/assets/javascripts/posts.js.coffee |CoffeeScript for the posts controller|
+|app/assets/stylesheets/posts.css.scss |Cascading style sheet for the posts controller|
+|app/assets/stylesheets/scaffolds.css.scss |Cascading style sheet to make the scaffolded views look better|
NOTE. While scaffolding will get you up and running quickly, the code it
generates is unlikely to be a perfect fit for your application. You'll most
--
cgit v1.2.3
From 06a8d16c8e0d87ab9a0dbba642aeb255f877cc8e Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:29:11 -0700
Subject: Update wording to be more explicit on what the timestamp fields track
---
railties/guides/source/getting_started.textile | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index d8e55eed60..01e0def226 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -609,12 +609,12 @@ class CreatePosts < ActiveRecord::Migration
end
-The above migration creates a method named +change+ which will be called when you
-run this migration. The action defined in that method is also reversible, which
+The above migration has one method named +change+ which will be called when you
+run this migration. The action defined in this method is also reversible, which
means Rails knows how to reverse the change made by this migration, in case you
-want to reverse it at later date. By default, when you run this migration it
-creates a +posts+ table with two string columns and a text column. It also
-creates two timestamp fields to track record creation and updating. More
+want to reverse it at later date. When you run this migration it will create a
++posts+ table with two string columns and a text column. It also creates two
+timestamp fields to allow Rails to track post creation and update times. More
information about Rails migrations can be found in the "Rails Database
Migrations":migrations.html guide.
--
cgit v1.2.3
From 1394c5447a8c27ab654556595468b7a0376c0cc9 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:31:07 -0700
Subject: Update wording to read better
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 01e0def226..d4bb55b5ba 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -634,7 +634,7 @@ table.
== CreatePosts: migrated (0.0020s) ===========================================
-NOTE. Because by default you're working in the development environment, this
+NOTE. Because you're working in the development environment by default, this
command will apply to the database defined in the +development+ section of your
+config/database.yml+ file. If you would like to execute migrations in another
environment, for instance in production, you must explicitly pass it when
--
cgit v1.2.3
From fc8f0a85b5c6869aed3f8d05b15c6b014deb054f Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:31:33 -0700
Subject: Add link to AR Validations and Callbacks to further explain
validations
---
railties/guides/source/getting_started.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index d4bb55b5ba..1f1976393f 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -705,7 +705,8 @@ end
These changes will ensure that all posts have a name and a title, and that the
title is at least five characters long. Rails can validate a variety of
conditions in a model, including the presence or uniqueness of columns, their
-format, and the existence of associated objects.
+format, and the existence of associated objects. Validations are covered in detail
+in "Active Record Validations and Callbacks":active_record_validations_callbacks.html#validations-overview
h4. Using the Console
--
cgit v1.2.3
From cb552f807e5bb2650791d17b01b6ac67c6023937 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:32:26 -0700
Subject: p.errors.full_messages is a little more human readable
---
railties/guides/source/getting_started.textile | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 1f1976393f..e88d0a7629 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -731,10 +731,8 @@ After the console loads, you can use it to work with your application's models:
updated_at: nil>
>> p.save
=> false
->> p.errors
-=> #["can't be blank",
- "is too short (minimum is 5 characters)"],
- :name=>["can't be blank"] }>
+>> p.errors.full_messages
+=> ["Name can't be blank", "Title can't be blank", "Title is too short (minimum is 5 characters)"]
This code shows creating a new +Post+ instance, attempting to save it and
--
cgit v1.2.3
From 9b96f7414e7380266ed5ccf582f55f1e10ba877b Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:33:29 -0700
Subject: Be explicit about changing code
---
railties/guides/source/getting_started.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index e88d0a7629..1d03698f4a 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -742,8 +742,8 @@ inspecting the +errors+ of the post.
When you're finished, type +exit+ and hit +return+ to exit the console.
TIP: Unlike the development web server, the console does not automatically load
-your code afresh for each line. If you make changes to your models while the
-console is open, type +reload!+ at the console prompt to load them.
+your code afresh for each line. If you make changes to your models (in your editor)
+while the console is open, type +reload!+ at the console prompt to load them.
h4. Listing All Posts
--
cgit v1.2.3
From 3e3872b5985f0b360571b97cdc1b3203989d40fd Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:35:08 -0700
Subject: Make the guide more friendly
- Changed Rails 3.0 to 3.0+
---
railties/guides/source/getting_started.textile | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 1d03698f4a..bd929a6ae2 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -747,8 +747,9 @@ while the console is open, type +reload!+ at the console prompt to load them.
h4. Listing All Posts
-The easiest place to start looking at functionality is with the code that lists
-all posts. Open the file +app/controllers/posts_controller.rb+ and look at the
+Let's dive into the Rails code a little deeper to see how the application is
+showing us the list of Posts. Open the file
++app/controllers/posts_controller.rb+ and look at the
+index+ action:
@@ -762,9 +763,9 @@ def index
end
-+Post.all+ calls the +Post+ model to return all of the posts currently in the
-database. The result of this call is an array of posts that we store in an
-instance variable called +@posts+.
++Post.all+ calls the all method on the +Post+ model, which returns all of
+the posts currently in the database. The result of this call is an array
+of Post records that we store in an instance variable called +@posts+.
TIP: For more information on finding records with Active Record, see "Active
Record Query Interface":active_record_querying.html.
@@ -815,7 +816,7 @@ and links. A few things to note in the view:
NOTE. In previous versions of Rails, you had to use +<%=h post.name %>+ so
that any HTML would be escaped before being inserted into the page. In Rails
-3.0, this is now the default. To get unescaped HTML, you now use +<%= raw
+3.0+, this is now the default. To get unescaped HTML, you now use +<%= raw
post.name %>+.
TIP: For more details on the rendering process, see "Layouts and Rendering in
@@ -829,9 +830,10 @@ Rails renders a view to the browser, it does so by putting the view's HTML into
a layout's HTML. In previous versions of Rails, the +rails generate scaffold+
command would automatically create a controller specific layout, like
+app/views/layouts/posts.html.erb+, for the posts controller. However this has
-been changed in Rails 3.0. An application specific +layout+ is used for all the
+been changed in Rails 3.0+. An application specific +layout+ is used for all the
controllers and can be found in +app/views/layouts/application.html.erb+. Open
-this layout in your editor and modify the +body+ tag:
+this layout in your editor and modify the +body+ tag to include the style directive
+below:
--
cgit v1.2.3
From 5e83491e976c867c57892d1542dbbcf571bada41 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 01:40:28 -0700
Subject: Be explicit on where the show.html.erb is located
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index bd929a6ae2..8f48c52442 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1011,7 +1011,7 @@ end
The +show+ action uses +Post.find+ to search for a single record in the database
by its id value. After finding the record, Rails displays it by using
-+show.html.erb+:
++app/views/posts/show.html.erb+:
<%= notice %>
--
cgit v1.2.3
From c0ee497436718ae6be50cfef5ee83473f1070fcd Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 03:12:13 -0700
Subject: Grammar change
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 8f48c52442..d0ba07a82d 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1116,7 +1116,7 @@ the controller.
h3. Adding a Second Model
-Now that you've seen how a model built with scaffolding looks like, it's time to
+Now that you've seen what a model built with scaffolding looks like, it's time to
add a second model to the application. The second model will handle comments on
blog posts.
--
cgit v1.2.3
From 0774f22941f6846acd79a07d43cd417cd09a1998 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 03:13:58 -0700
Subject: Convert tables to table format
---
railties/guides/source/getting_started.textile | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index d0ba07a82d..f387dddce8 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1135,9 +1135,11 @@ $ rails generate model Comment commenter:string body:text post:references
This command will generate four files:
-* +app/models/comment.rb+ - The model.
-* +db/migrate/20100207235629_create_comments.rb+ - The migration.
-* +test/unit/comment_test.rb+ and +test/fixtures/comments.yml+ - The test harness.
+|_.File |_.Purpose|
+|db/migrate/20100207235629_create_comments.rb | Migration to create the comments table in your database (your name will include a different timestamp) |
+| app/models/comment.rb | The Comment model |
+| test/unit/comment_test.rb | Unit testing harness for the comments model |
+| test/fixtures/comments.yml | Sample comments for use in testing |
First, take a look at +comment.rb+:
@@ -1258,13 +1260,14 @@ $ rails generate controller Comments
This creates six files and one empty directory:
-* +app/controllers/comments_controller.rb+ - The controller.
-* +app/helpers/comments_helper.rb+ - A view helper file.
-* +test/functional/comments_controller_test.rb+ - The functional tests for the controller.
-* +test/unit/helpers/comments_helper_test.rb+ - The unit tests for the helper.
-* +app/views/comments/+ - Views of the controller are stored here.
-* +app/assets/stylesheets/comment.css.scss+ - Cascading style sheet for the controller.
-* +app/assets/javascripts/comment.js.coffee+ - CoffeeScript for the controller.
+|_.File/Directory |_.Purpose |
+| app/controllers/comments_controller.rb | The Comments controller |
+| app/views/comments/ | Views of the controller are stored here |
+| test/functional/comments_controller_test.rb | The functional tests for the controller |
+| app/helpers/comments_helper.rb | A view helper file |
+| test/unit/helpers/comments_helper_test.rb | The unit tests for the helper |
+| app/assets/javascripts/comment.js.coffee | CoffeeScript for the controller |
+| app/assets/stylesheets/comment.css.scss | Cascading style sheet for the controller |
Like with any blog, our readers will create their comments directly after
reading the post, and once they have added their comment, will be sent back to
--
cgit v1.2.3
From a3156ac0f2d57ca5a57c035530ff5b49f81716f3 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 03:15:22 -0700
Subject: Add output for add_index command
---
railties/guides/source/getting_started.textile | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index f387dddce8..8faacdd03e 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1186,8 +1186,10 @@ run against the current database, so in this case you will just see:
== CreateComments: migrating =================================================
-- create_table(:comments)
- -> 0.0017s
-== CreateComments: migrated (0.0018s) ========================================
+ -> 0.0008s
+-- add_index(:comments, :post_id)
+ -> 0.0003s
+== CreateComments: migrated (0.0012s) ========================================
h4. Associating Models
--
cgit v1.2.3
From 50a9de514f8724b04d3681aa9ca228a8ca490909 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 03:15:56 -0700
Subject: Update guide to use Ruby 1.9 hash syntax
---
railties/guides/source/getting_started.textile | 88 +++++++++++++-------------
1 file changed, 43 insertions(+), 45 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 8faacdd03e..8f34e87e9a 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -524,10 +524,10 @@ Blog::Application.routes.draw do
#...
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- root :to => "home#index"
+ root to: "home#index"
-The +root :to => "home#index"+ tells Rails to map the root action to the home
+The +root to: "home#index"+ tells Rails to map the root action to the home
controller's index action.
Now if you navigate to "http://localhost:3000":http://localhost:3000 in your
@@ -696,9 +696,9 @@ Open the +app/models/post.rb+ file and edit it:
class Post < ActiveRecord::Base
- validates :name, :presence => true
- validates :title, :presence => true,
- :length => { :minimum => 5 }
+ validates :name, presence: true
+ validates :title, presence: true,
+ length: { minimum: 5 }
end
@@ -725,7 +725,7 @@ open a console that will roll back any changes you make by using rails conso
After the console loads, you can use it to work with your application's models:
->> p = Post.new(:content => "A new post")
+>> p = Post.new(content: "A new post")
=> #
@@ -758,11 +758,15 @@ def index
respond_to do |format|
format.html # index.html.erb
- format.json { render :json => @posts }
+ format.json { render json: @posts }
end
end
+TIP: This Guide was written using Ruby 1.9.2. If you are using Ruby 1.8.7, some of
+the syntax may look slightly different. For example, the hash syntax changed from
+render :json => @posts (1.8.7) to render json: @posts (1.9.2).
+
+Post.all+ calls the all method on the +Post+ model, which returns all of
the posts currently in the database. The result of this call is an array
of Post records that we store in an instance variable called +@posts+.
@@ -797,8 +801,7 @@ Here's +app/views/posts/index.html.erb+:
<%= post.content %>
<%= link_to 'Show', post %>
<%= link_to 'Edit', edit_post_path(post) %>
-
<%= link_to 'Destroy', post, :confirm => 'Are you sure?',
- :method => :delete %>
+
<%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %>
<% end %>
@@ -866,7 +869,7 @@ def new
respond_to do |format|
format.html # new.html.erb
- format.json { render :json => @post }
+ format.json { render json: @post }
end
end
@@ -958,14 +961,11 @@ def create
respond_to do |format|
if @post.save
- format.html { redirect_to(@post,
- :notice => 'Post was successfully created.') }
- format.json { render :json => @post,
- :status => :created, :location => @post }
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
+ format.json { render json: @post, status: :created, location: @post }
else
- format.html { render :action => "new" }
- format.json { render :json => @post.errors,
- :status => :unprocessable_entity }
+ format.html { render action: "new" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
@@ -1003,8 +1003,8 @@ def show
@post = Post.find(params[:id])
respond_to do |format|
- format.html # show.html.erb
- format.json { render :json => @post }
+ format.html # show.html.erb
+ format.json { render json: @post }
end
end
@@ -1073,13 +1073,11 @@ def update
respond_to do |format|
if @post.update_attributes(params[:post])
- format.html { redirect_to(@post,
- :notice => 'Post was successfully updated.') }
- format.json { render :json => {}, :status => :ok }
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
+ format.json { head :ok }
else
- format.html { render :action => "edit" }
- format.json { render :json => @post.errors,
- :status => :unprocessable_entity }
+ format.html { render action: "edit" }
+ format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
@@ -1215,9 +1213,9 @@ You'll need to edit the +post.rb+ file to add the other side of the association:
class Post < ActiveRecord::Base
- validates :name, :presence => true
- validates :title, :presence => true,
- :length => { :minimum => 5 }
+ validates :name, presence: true
+ validates :title, presence: true,
+ length: { :minimum: 5 }
has_many :comments
end
@@ -1559,8 +1557,8 @@ So first, let's add the delete link in the
--
cgit v1.2.3
From e1099eb4fdb64b82485843a569ecd5006aa3dad8 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 13 Nov 2011 21:50:18 +0530
Subject: Revert "Update guide to use Ruby 1.9 hash syntax"
This reverts commit 50a9de514f8724b04d3681aa9ca228a8ca490909.
Reason: Let's keep the guides at 1.8 syntax
---
railties/guides/source/getting_started.textile | 88 +++++++++++++-------------
1 file changed, 45 insertions(+), 43 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 8f34e87e9a..8faacdd03e 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -524,10 +524,10 @@ Blog::Application.routes.draw do
#...
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- root to: "home#index"
+ root :to => "home#index"
-The +root to: "home#index"+ tells Rails to map the root action to the home
+The +root :to => "home#index"+ tells Rails to map the root action to the home
controller's index action.
Now if you navigate to "http://localhost:3000":http://localhost:3000 in your
@@ -696,9 +696,9 @@ Open the +app/models/post.rb+ file and edit it:
class Post < ActiveRecord::Base
- validates :name, presence: true
- validates :title, presence: true,
- length: { minimum: 5 }
+ validates :name, :presence => true
+ validates :title, :presence => true,
+ :length => { :minimum => 5 }
end
@@ -725,7 +725,7 @@ open a console that will roll back any changes you make by using rails conso
After the console loads, you can use it to work with your application's models:
->> p = Post.new(content: "A new post")
+>> p = Post.new(:content => "A new post")
=> #
@@ -758,15 +758,11 @@ def index
respond_to do |format|
format.html # index.html.erb
- format.json { render json: @posts }
+ format.json { render :json => @posts }
end
end
-TIP: This Guide was written using Ruby 1.9.2. If you are using Ruby 1.8.7, some of
-the syntax may look slightly different. For example, the hash syntax changed from
-render :json => @posts (1.8.7) to render json: @posts (1.9.2).
-
+Post.all+ calls the all method on the +Post+ model, which returns all of
the posts currently in the database. The result of this call is an array
of Post records that we store in an instance variable called +@posts+.
@@ -801,7 +797,8 @@ Here's +app/views/posts/index.html.erb+:
<%= post.content %>
<%= link_to 'Show', post %>
<%= link_to 'Edit', edit_post_path(post) %>
-
<%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %>
+
<%= link_to 'Destroy', post, :confirm => 'Are you sure?',
+ :method => :delete %>
<% end %>
@@ -869,7 +866,7 @@ def new
respond_to do |format|
format.html # new.html.erb
- format.json { render json: @post }
+ format.json { render :json => @post }
end
end
@@ -961,11 +958,14 @@ def create
respond_to do |format|
if @post.save
- format.html { redirect_to @post, notice: 'Post was successfully created.' }
- format.json { render json: @post, status: :created, location: @post }
+ format.html { redirect_to(@post,
+ :notice => 'Post was successfully created.') }
+ format.json { render :json => @post,
+ :status => :created, :location => @post }
else
- format.html { render action: "new" }
- format.json { render json: @post.errors, status: :unprocessable_entity }
+ format.html { render :action => "new" }
+ format.json { render :json => @post.errors,
+ :status => :unprocessable_entity }
end
end
end
@@ -1003,8 +1003,8 @@ def show
@post = Post.find(params[:id])
respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @post }
+ format.html # show.html.erb
+ format.json { render :json => @post }
end
end
@@ -1073,11 +1073,13 @@ def update
respond_to do |format|
if @post.update_attributes(params[:post])
- format.html { redirect_to @post, notice: 'Post was successfully updated.' }
- format.json { head :ok }
+ format.html { redirect_to(@post,
+ :notice => 'Post was successfully updated.') }
+ format.json { render :json => {}, :status => :ok }
else
- format.html { render action: "edit" }
- format.json { render json: @post.errors, status: :unprocessable_entity }
+ format.html { render :action => "edit" }
+ format.json { render :json => @post.errors,
+ :status => :unprocessable_entity }
end
end
end
@@ -1213,9 +1215,9 @@ You'll need to edit the +post.rb+ file to add the other side of the association:
class Post < ActiveRecord::Base
- validates :name, presence: true
- validates :title, presence: true,
- length: { :minimum: 5 }
+ validates :name, :presence => true
+ validates :title, :presence => true,
+ :length => { :minimum => 5 }
has_many :comments
end
@@ -1557,8 +1559,8 @@ So first, let's add the delete link in the
--
cgit v1.2.3
From c8c08bd000c00817d2f17f560f392965fd82229b Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 13 Nov 2011 21:57:39 +0530
Subject: Revert "Use rails help new instead of rails new -h"
This reverts commit 6ac65c92029d3eefd101f9458d86bae0314cd14c.
---
railties/guides/source/getting_started.textile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 8faacdd03e..98e7c93dc7 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -263,7 +263,8 @@ $ rails new blog
This will create a Rails application called Blog in a directory called blog.
TIP: You can see all of the switches that the Rails application builder accepts
-by running rails help new.
+by running
+rails new -h.
After you create the blog application, switch to its folder to continue work
directly in that application:
--
cgit v1.2.3
From af51409de433f14d251f7f229a2f651d3ddf7b1c Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 13 Nov 2011 22:07:54 +0530
Subject: Revert "Move Tip up higher so users who are fine with SQLite can skip
to the next section"
This reverts commit 4bf057b8661754948681a18cf17ff5676518d774.
Reason: Prefer to keep the configuration of all databases at the same
level
---
railties/guides/source/getting_started.textile | 34 ++++++++++++--------------
1 file changed, 16 insertions(+), 18 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 98e7c93dc7..9e774ff298 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -335,17 +335,7 @@ and PostgreSQL "out of the box", and has plugins for many database systems. If
you are using a database in a production environment Rails most likely has an
adapter for it.
-h5. Other database configuration options
-
-TIP: You don't have to update the database configurations manually. If you look at the
-options of the application generator, you will see that one of the options
-is named --database. This option allows you to choose an adapter from a
-list of the most used relational databases. You can even run the generator
-repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting
- of the +config/database.yml+ file, your application will be configured for MySQL
-instead of SQLite.
-
-h6. Configuring a MySQL Database
+h5. Configuring a MySQL Database
If you choose to use MySQL instead of the shipped SQLite3 database, your
+config/database.yml+ will look a little different. Here's the development
@@ -366,7 +356,7 @@ If your development computer's MySQL installation includes a root user with an
empty password, this configuration should work for you. Otherwise, change the
username and password in the +development+ section as appropriate.
-h6. Configuring a PostgreSQL Database
+h5. Configuring a PostgreSQL Database
If you choose to use PostgreSQL, your +config/database.yml+ will be customized
to use PostgreSQL databases:
@@ -381,9 +371,9 @@ development:
password:
-h6. Configuring an SQLite3 Database for JRuby Platform
+h5. Configuring an SQLite3 Database for JRuby Platform
-If you choose to use SQLite3 and using JRuby, your +config/database.yml+ will
+If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will
look a little different. Here's the development section:
@@ -392,9 +382,9 @@ development:
database: db/development.sqlite3
-h6. Configuring a MySQL Database for JRuby Platform
+h5. Configuring a MySQL Database for JRuby Platform
-If you choose to use MySQL and using JRuby, your +config/database.yml+ will look
+If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look
a little different. Here's the development section:
@@ -405,9 +395,9 @@ development:
password:
-h6. Configuring a PostgreSQL Database for JRuby Platform
+h5. Configuring a PostgreSQL Database for JRuby Platform
-Finally if you choose to use PostgreSQL and using JRuby, your
+Finally if you choose to use PostgreSQL and are using JRuby, your
+config/database.yml+ will look a little different. Here's the development
section:
@@ -422,6 +412,14 @@ development:
Change the username and password in the +development+ section as appropriate.
+TIP: You don't have to update the database configurations manually. If you look at the
+options of the application generator, you will see that one of the options
+is named --database. This option allows you to choose an adapter from a
+list of the most used relational databases. You can even run the generator
+repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting
+ of the +config/database.yml+ file, your application will be configured for MySQL
+instead of SQLite.
+
h4. Creating the Database
Now that you have your database configured, it's time to have Rails create an
--
cgit v1.2.3
From 30122307a1fe6645d6a75dedceca40a440f2f969 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 13 Nov 2011 22:27:44 +0530
Subject: copy edits in getting started guide
---
railties/guides/source/getting_started.textile | 27 ++++++++++++--------------
1 file changed, 12 insertions(+), 15 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 9e774ff298..5f370615ca 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -221,8 +221,7 @@ h3. Creating a New Rails Project
The best way to use this guide is to follow each step as it happens, no code or
step needed to make this example application has been left out, so you can
-literally follow along step by step. If you need to see the completed code, you
-can download it from "Getting Started Code":https://github.com/mikel/getting-started-code.
+literally follow along step by step. You can get the complete code "here":https://github.com/lifo/docrails/tree/master/railties/guides/code/getting_started.
By following along with this guide, you'll create a Rails project called blog, a
(very) simple weblog. Before you can start building the application, you need to
@@ -246,7 +245,7 @@ To verify that you have everything installed correctly, you should be able to ru
the following:
-# rails --version
+$ rails --version
If it says something like "Rails 3.1.1" you are ready to continue.
@@ -273,7 +272,7 @@ directly in that application:
$ cd blog
-The 'rails new blog' command we ran above created a folder in your working directory
+The 'rails new blog' command we ran above created a folder in your working directory
called blog. The blog folder has a number of auto-generated folders
that make up the structure of a Rails application. Most of the work in
this tutorial will happen in the app/ folder, but here's a basic
@@ -304,7 +303,7 @@ this file in a new Rails application, you'll see a default database
configured to use SQLite3. The file contains sections for three different
environments in which Rails can run by default:
-* The +development+ environment is used on your development/local computer as you interact
+* The +development+ environment is used on your development/local computer as you interact
manually with the application.
* The +test+ environment is used when running automated tests.
* The +production+ environment is used when you deploy your application for the world to use.
@@ -514,8 +513,7 @@ file_ which holds entries in a special DSL (domain-specific language) that tells
Rails how to connect incoming requests to controllers and actions. This file
contains many sample routes on commented lines, and one of them actually shows
you how to connect the root of your site to a specific controller and action.
-Find the line beginning with +root :to+, uncomment it by removing the pound sign
-at the beginning of the line. It should look something like the following:
+Find the line beginning with +root :to+ and uncomment it. It should look something like the following:
Blog::Application.routes.draw do
@@ -608,11 +606,11 @@ class CreatePosts < ActiveRecord::Migration
end
-The above migration has one method named +change+ which will be called when you
+The above migration creates a method named +change+ which will be called when you
run this migration. The action defined in this method is also reversible, which
means Rails knows how to reverse the change made by this migration, in case you
-want to reverse it at later date. When you run this migration it will create a
-+posts+ table with two string columns and a text column. It also creates two
+want to reverse it later. When you run this migration it will create a
++posts+ table with two string columns and a text column. It also creates two
timestamp fields to allow Rails to track post creation and update times. More
information about Rails migrations can be found in the "Rails Database
Migrations":migrations.html guide.
@@ -704,7 +702,7 @@ end
These changes will ensure that all posts have a name and a title, and that the
title is at least five characters long. Rails can validate a variety of
conditions in a model, including the presence or uniqueness of columns, their
-format, and the existence of associated objects. Validations are covered in detail
+format, and the existence of associated objects. Validations are covered in detail
in "Active Record Validations and Callbacks":active_record_validations_callbacks.html#validations-overview
h4. Using the Console
@@ -747,7 +745,7 @@ while the console is open, type +reload!+ at the console prompt to load them.
h4. Listing All Posts
Let's dive into the Rails code a little deeper to see how the application is
-showing us the list of Posts. Open the file
+showing us the list of Posts. Open the file
+app/controllers/posts_controller.rb+ and look at the
+index+ action:
@@ -762,9 +760,8 @@ def index
end
-+Post.all+ calls the all method on the +Post+ model, which returns all of
-the posts currently in the database. The result of this call is an array
-of Post records that we store in an instance variable called +@posts+.
++Post.all+ returns all of the posts currently in the database as an array
+of +Post+ records that we store in an instance variable called +@posts+.
TIP: For more information on finding records with Active Record, see "Active
Record Query Interface":active_record_querying.html.
--
cgit v1.2.3
From 8971cca7d0cef3ce452bf44fb09ae628419d8ea1 Mon Sep 17 00:00:00 2001
From: Jason Noble
Date: Sun, 13 Nov 2011 10:20:03 -0700
Subject: Move tooltip on re-running rails new with a different --database
option
---
railties/guides/source/getting_started.textile | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 8a0a70efad..fde83ae730 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -308,6 +308,14 @@ manually with the application.
* The +test+ environment is used when running automated tests.
* The +production+ environment is used when you deploy your application for the world to use.
+TIP: You don't have to update the database configurations manually. If you look at the
+options of the application generator, you will see that one of the options
+is named --database. This option allows you to choose an adapter from a
+list of the most used relational databases. You can even run the generator
+repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting
+ of the +config/database.yml+ file, your application will be configured for MySQL
+instead of SQLite. Detailed examples of the common database connections are below.
+
h5. Configuring an SQLite3 Database
Rails comes with built-in support for "SQLite3":http://www.sqlite.org, which is
@@ -411,14 +419,6 @@ development:
Change the username and password in the +development+ section as appropriate.
-TIP: You don't have to update the database configurations manually. If you look at the
-options of the application generator, you will see that one of the options
-is named --database. This option allows you to choose an adapter from a
-list of the most used relational databases. You can even run the generator
-repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting
- of the +config/database.yml+ file, your application will be configured for MySQL
-instead of SQLite.
-
h4. Creating the Database
Now that you have your database configured, it's time to have Rails create an
--
cgit v1.2.3
From df08273d1420ee4879931f508fe2953235c707ef Mon Sep 17 00:00:00 2001
From: Sergey Parizhskiy
Date: Tue, 15 Nov 2011 13:09:41 +0200
Subject: made url to a github issues a bit shorter - no need in a page param
when it's a first page
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 80c3cf6e1a..1cd70404a3 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -215,7 +215,7 @@ TIP: You may want to "put your git branch name in your shell prompt":http://qugs
h3. Helping to Resolve Existing Issues
-As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the "Everyone's Issues":https://github.com/rails/rails/issues?sort=created&direction=desc&state=open&page=1 list in GitHub Issues, you'll find lots of issues already requiring attention. What can you do for these? Quite a bit, actually:
+As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the "Everyone's Issues":https://github.com/rails/rails/issues?sort=created&direction=desc&state=open list in GitHub Issues, you'll find lots of issues already requiring attention. What can you do for these? Quite a bit, actually:
h4. Verifying Bug Reports
--
cgit v1.2.3
From bc00514b6236d701d3e660c4ec365a767a070a91 Mon Sep 17 00:00:00 2001
From: rpq
Date: Tue, 15 Nov 2011 23:20:21 -0500
Subject: added comma
---
railties/guides/source/asset_pipeline.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 6ff5e87b6d..3681501293 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -438,7 +438,7 @@ location ~ ^/assets/ {
}
-When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. On the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
+When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once, Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. On the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.
Nginx is able to do this automatically enabling +gzip_static+:
--
cgit v1.2.3
From 64a3175eea3c121f30a5a24034aa1ed400c80b12 Mon Sep 17 00:00:00 2001
From: capps
Date: Wed, 16 Nov 2011 15:57:54 -0800
Subject: "denoted" instead of "donated" "parentheses" instead of "use
brackets"
---
railties/guides/source/i18n.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 2d4cc13571..e9477e84cf 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -231,7 +231,7 @@ end
Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed).
-If you don't want to force the use of a locale in your routes you can use an optional path scope (donated by the use brackets) like so:
+If you don't want to force the use of a locale in your routes you can use an optional path scope (denoted by the parentheses) like so:
# config/routes.rb
--
cgit v1.2.3
From 0af93089deaf6dc9428c0f2f7a376cdb6f81daee Mon Sep 17 00:00:00 2001
From: Alex Tambellini
Date: Thu, 17 Nov 2011 09:44:17 -0500
Subject: Move schema_format :sql config setting from test.rb to application.rb
I've moved the schema_format :sql config setting to application.rb because you would
never enable this only for the test environment. If you use database constraints
or database specific data types you would want all of your environments to use them.
---
railties/guides/code/getting_started/config/application.rb | 5 +++++
railties/guides/code/getting_started/config/environments/test.rb | 5 -----
2 files changed, 5 insertions(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/config/application.rb b/railties/guides/code/getting_started/config/application.rb
index e914b5a80e..e16da30f72 100644
--- a/railties/guides/code/getting_started/config/application.rb
+++ b/railties/guides/code/getting_started/config/application.rb
@@ -39,6 +39,11 @@ module Blog
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+ # Use SQL instead of Active Record's schema dumper when creating the database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
# Enable the asset pipeline
config.assets.enabled = true
diff --git a/railties/guides/code/getting_started/config/environments/test.rb b/railties/guides/code/getting_started/config/environments/test.rb
index 833241ace3..08697cbbc9 100644
--- a/railties/guides/code/getting_started/config/environments/test.rb
+++ b/railties/guides/code/getting_started/config/environments/test.rb
@@ -29,11 +29,6 @@ Blog::Application.configure do
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
- # Use SQL instead of Active Record's schema dumper when creating the test database.
- # This is necessary if your schema can't be completely dumped by the schema dumper,
- # like if you have constraints or database-specific column types
- # config.active_record.schema_format = :sql
-
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
--
cgit v1.2.3
From 8d17af23ef5202e7c28bbf701e247bce6011df07 Mon Sep 17 00:00:00 2001
From: Sunny Ripert
Date: Thu, 17 Nov 2011 17:05:53 +0100
Subject: Guides: better example to find the last sent email
---
railties/guides/source/testing.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile
index 2341a3522c..5dbbe2c0f0 100644
--- a/railties/guides/source/testing.textile
+++ b/railties/guides/source/testing.textile
@@ -927,7 +927,7 @@ class UserControllerTest < ActionController::TestCase
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
post :invite_friend, :email => 'friend@example.com'
end
- invite_email = ActionMailer::Base.deliveries.first
+ invite_email = ActionMailer::Base.deliveries.last
assert_equal "You have been invited by me@example.com", invite_email.subject
assert_equal 'friend@example.com', invite_email.to[0]
--
cgit v1.2.3
From 9b534060bfafbf1db36e73bb3e538b8c412dcc54 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 18 Nov 2011 01:17:21 +0530
Subject: update guide: db:structure:dump produces structure.sql now
---
railties/guides/source/migrations.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 23e36b39f9..5b52a93853 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -658,7 +658,7 @@ In many ways this is exactly what it is. This file is created by inspecting the
There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
-Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
+Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
h4. Schema Dumps and Source Control
--
cgit v1.2.3
From d57d8098fc269a26ea0051a9027a33af1a9a4b2b Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Thu, 17 Nov 2011 23:07:06 +0100
Subject: warn the user values are directly interpolated into _html translation
strings
---
railties/guides/source/i18n.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 2d4cc13571..43afa6c9e2 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -634,6 +634,18 @@ en:
!images/i18n/demo_html_safe.png(i18n demo html safe)!
+Please note that values are interpolated directly into the translation.
+If they need to be escaped you need to pass them already escaped in the +t+ call.
+
+
+# config/locales/en.yml
+en:
+ welcome_html: Welcome %{name}!
+
+<%# Note the call to h() to avoid injection %>
+<%= t('welcome_html', :name => h(user.name)) %>
+
+
h3. How to Store your Custom Translations
The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and YAML format. [2]
--
cgit v1.2.3
From 1079724fe643fe63e6d58a37274c2cf0ff172a8b Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Thu, 17 Nov 2011 23:59:19 +0100
Subject: Revert "warn the user values are directly interpolated into _html
translation strings"
Reason: After another round of discussion, it has been
decided to let interpolation deal with unsafe strings
as it should do.
This reverts commit d57d8098fc269a26ea0051a9027a33af1a9a4b2b.
---
railties/guides/source/i18n.textile | 12 ------------
1 file changed, 12 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile
index 43afa6c9e2..2d4cc13571 100644
--- a/railties/guides/source/i18n.textile
+++ b/railties/guides/source/i18n.textile
@@ -634,18 +634,6 @@ en:
!images/i18n/demo_html_safe.png(i18n demo html safe)!
-Please note that values are interpolated directly into the translation.
-If they need to be escaped you need to pass them already escaped in the +t+ call.
-
-
-# config/locales/en.yml
-en:
- welcome_html: Welcome %{name}!
-
-<%# Note the call to h() to avoid injection %>
-<%= t('welcome_html', :name => h(user.name)) %>
-
-
h3. How to Store your Custom Translations
The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and YAML format. [2]
--
cgit v1.2.3
From 9d035292ba39fcb046656ceb28e7a2f10cdb7f9c Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 18 Nov 2011 23:10:12 +0530
Subject: remove unneeded params from issue tracker url
---
railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile
index 1cd70404a3..37ead2bff2 100644
--- a/railties/guides/source/contributing_to_ruby_on_rails.textile
+++ b/railties/guides/source/contributing_to_ruby_on_rails.textile
@@ -215,7 +215,7 @@ TIP: You may want to "put your git branch name in your shell prompt":http://qugs
h3. Helping to Resolve Existing Issues
-As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the "Everyone's Issues":https://github.com/rails/rails/issues?sort=created&direction=desc&state=open list in GitHub Issues, you'll find lots of issues already requiring attention. What can you do for these? Quite a bit, actually:
+As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the "Everyone's Issues":https://github.com/rails/rails/issues list in GitHub Issues, you'll find lots of issues already requiring attention. What can you do for these? Quite a bit, actually:
h4. Verifying Bug Reports
--
cgit v1.2.3
From dda6787f44a4e9a90cc28b3efee5b63c7d8cd023 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 19 Nov 2011 00:07:50 +0530
Subject: mailer guide - update info about using default host. Fixes #3642
---
railties/guides/source/action_mailer_basics.textile | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index ad5b848d2c..26c95be031 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -362,21 +362,14 @@ When using named routes you only need to supply the +:host+:
Email clients have no web context and so paths have no base URL to form complete web addresses. Thus, when using named routes only the "_url" variant makes sense.
-It is also possible to set a default host that will be used in all mailers by setting the +:host+ option in the +ActionMailer::Base.default_url_options+ hash as follows:
+It is also possible to set a default host that will be used in all mailers by setting the :host option as a configuration option in config/application.rb:
-class UserMailer < ActionMailer::Base
- default_url_options[:host] = "example.com"
-
- def welcome_email(user)
- @user = user
- @url = user_url(@user)
- mail(:to => user.email,
- :subject => "Welcome to My Awesome Site")
- end
-end
+config.action_mailer.default_url_options = { :host => "example.com" }
+If you use this setting, you should pass the :only_path => false option when using +url_for+. This will ensure that absolute URLs are generated because the +url_for+ view helper will, by default, generate relative URLs when a :host option isn't explicitly provided.
+
h4. Sending Multipart Emails
Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have +welcome_email.text.erb+ and +welcome_email.html.erb+ in +app/views/user_mailer+, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts.
--
cgit v1.2.3
From ed5586fa9e2f585d2edeb600ab1c884e419f9f72 Mon Sep 17 00:00:00 2001
From: Matt Burke
Date: Fri, 18 Nov 2011 14:10:17 -0500
Subject: Add config.active_record.identity_map to the configuration guide.
---
railties/guides/source/configuring.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index cd6e7d116e..809948b41e 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -263,6 +263,8 @@ h4. Configuring Active Record
* +config.active_record.whitelist_attributes+ will create an empty whitelist of attributes available for mass-assignment security for all models in your app.
+* +config.active_record.identity_map+ controls whether the identity map is enabled, and is false by default.
+
The MySQL adapter adds one additional configuration option:
* +ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether Active Record will consider all +tinyint(1)+ columns in a MySQL database to be booleans and is true by default.
--
cgit v1.2.3
From 6b4939c3fd22924ee3d906f08fe739d848f80a3d Mon Sep 17 00:00:00 2001
From: James Dean Shepherd
Date: Sun, 20 Nov 2011 02:34:55 +0000
Subject: Added links to the 'Rails Initialization Guide', marked as a work in
progress
---
railties/guides/source/index.html.erb | 4 ++++
railties/guides/source/layout.html.erb | 1 +
2 files changed, 5 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index c9a8c4fa5c..a8e12174ed 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -134,6 +134,10 @@ Ruby on Rails Guides
<%= guide('Asset Pipeline', 'asset_pipeline.html') do %>
This guide documents the asset pipeline.
<% end %>
+
+<%= guide('The Rails Initialization Process', 'initialization.html', :work_in_progress => true) do %>
+
This guide explains the internals of the Rails initialization process as of Rails 3.1
--
cgit v1.2.3
From 5660a16d56bb738979c47bf3dea16a40c2547b16 Mon Sep 17 00:00:00 2001
From: James Dean Shepherd
Date: Sun, 20 Nov 2011 02:36:50 +0000
Subject: Minor grammar, typo & readability fixes for beginning of Rails
Initialization guide
---
railties/guides/source/initialization.textile | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 036b356a37..5ae9cf0f2b 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -17,7 +17,7 @@ As of Rails 3, +script/server+ has become +rails server+. This was done to centr
h4. +bin/rails+
-The actual +rails+ command is kept in _bin/rails_ at the and goes like this:
+The actual +rails+ command is kept in _bin/rails_:
#!/usr/bin/env ruby
@@ -31,7 +31,7 @@ rescue LoadError
end
-This file will attempt to load +rails/cli+ and if it cannot find it then add the +railties/lib+ path to the load path (+$:+) and will then try to require it again.
+This file will attempt to load +rails/cli+. If it cannot find it then +railties/lib+ is added to the load path (+$:+) before retrying.
h4. +railties/lib/rails/cli.rb+
@@ -56,7 +56,7 @@ else
end
-The +rbconfig+ file here is out of Ruby's standard library and provides us with the +RbConfig+ class which contains useful information dependent on how Ruby was compiled. We'll see this in use in +railties/lib/rails/script_rails_loader+.
+The +rbconfig+ file from the Ruby standard library provides us with the +RbConfig+ class which contains detailed information about the Ruby environment, including how Ruby was compiled. We can see this in use in +railties/lib/rails/script_rails_loader+.
require 'pathname'
@@ -71,7 +71,7 @@ module Rails
end
-The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method.
+The +rails/script_rails_loader+ file uses +RbConfig::Config+ to obtain the +bin_dir+ and +ruby_install_name+ values for the configuration which together form the path to the Ruby interpreter. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method.
Back in +rails/cli+, the next line is this:
@@ -79,7 +79,7 @@ Back in +rails/cli+, the next line is this:
Rails::ScriptRailsLoader.exec_script_rails!
-This method is defined in +rails/script_rails_loader+ like this:
+This method is defined in +rails/script_rails_loader+:
def self.exec_script_rails!
@@ -96,7 +96,7 @@ rescue SystemCallError
end
-This method will first check if the current working directory (+cwd+) is a Rails application or is a subdirectory of one. The way to determine this is defined in the +in_rails_application?+ method like this:
+This method will first check if the current working directory (+cwd+) is a Rails application or a subdirectory of one. This is determined by the +in_rails_application?+ method:
def self.in_rails_application?
@@ -104,7 +104,7 @@ def self.in_rails_application?
end
-The +SCRIPT_RAILS+ constant defined earlier is used here, with +File.exists?+ checking for its presence in the current directory. If this method returns +false+, then +in_rails_application_subdirectory?+ will be used:
+The +SCRIPT_RAILS+ constant defined earlier is used here, with +File.exists?+ checking for its presence in the current directory. If this method returns +false+ then +in_rails_application_subdirectory?+ will be used:
def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
@@ -112,17 +112,17 @@ def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd))
end
-This climbs the directory tree until it reaches a path which contains a +script/rails+ file. If a directory is reached which contains this file then this line will run:
+This climbs the directory tree until it reaches a path which contains a +script/rails+ file. If a directory containing this file is reached then this line will run:
exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application?
-This is effectively the same as doing +ruby script/rails [arguments]+. Where +[arguments]+ at this point in time is simply "server".
+This is effectively the same as running +ruby script/rails [arguments]+, where +[arguments]+ at this point in time is simply "server".
h4. +script/rails+
-This file looks like this:
+This file is as follows:
APP_PATH = File.expand_path('../../config/application', __FILE__)
@@ -130,7 +130,7 @@ require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
-The +APP_PATH+ constant here will be used later in +rails/commands+. The +config/boot+ file that +script/rails+ references is the +config/boot.rb+ file in our application which is responsible for loading Bundler and setting it up.
+The +APP_PATH+ constant will be used later in +rails/commands+. The +config/boot+ file referenced here is the +config/boot.rb+ file in our application which is responsible for loading Bundler and setting it up.
h4. +config/boot.rb+
--
cgit v1.2.3
From 5c61b7230eaa316ce64f4031234b425c35668988 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 22 Nov 2011 23:14:13 +0530
Subject: Revert "Added links to the 'Rails Initialization Guide', marked as a
work in progress"
This reverts commit 6b4939c3fd22924ee3d906f08fe739d848f80a3d.
Reason: This guide is still incomplete and is not yet reviewed or ready
to go to the index.
---
railties/guides/source/index.html.erb | 4 ----
railties/guides/source/layout.html.erb | 1 -
2 files changed, 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
index a8e12174ed..c9a8c4fa5c 100644
--- a/railties/guides/source/index.html.erb
+++ b/railties/guides/source/index.html.erb
@@ -134,10 +134,6 @@ Ruby on Rails Guides
<%= guide('Asset Pipeline', 'asset_pipeline.html') do %>
This guide documents the asset pipeline.
<% end %>
-
-<%= guide('The Rails Initialization Process', 'initialization.html', :work_in_progress => true) do %>
-
This guide explains the internals of the Rails initialization process as of Rails 3.1
--
cgit v1.2.3
From 05e02deb686fc21f99c2d1dcf3abc987796e0e19 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune
Date: Tue, 22 Nov 2011 15:16:23 -0500
Subject: Make explicit the default media when calling stylesheet_tag and
change the default generators.
---
.../guides/code/getting_started/app/views/layouts/application.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/code/getting_started/app/views/layouts/application.html.erb b/railties/guides/code/getting_started/app/views/layouts/application.html.erb
index 1e1e4b9a99..7fd6b4f516 100644
--- a/railties/guides/code/getting_started/app/views/layouts/application.html.erb
+++ b/railties/guides/code/getting_started/app/views/layouts/application.html.erb
@@ -2,7 +2,7 @@
Blog
- <%= stylesheet_link_tag "application" %>
+ <%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
--
cgit v1.2.3
From 6da52c617e2a075b9d9e7142786f316d8f2c7930 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 23 Nov 2011 23:22:46 +0000
Subject: Remove listings from the serialization guide that won't make 3.2.
---
railties/guides/source/serializers.textile | 37 ------------------------------
1 file changed, 37 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
index 86a5e5ac8d..efc7cbf248 100644
--- a/railties/guides/source/serializers.textile
+++ b/railties/guides/source/serializers.textile
@@ -459,25 +459,6 @@ In other words, if a +PostSerializer+ is trying to serialize comments, it will f
look for +PostSerializer::CommentSerializer+ before falling back to +CommentSerializer+
and finally +comment.as_json+.
-h3. Optional Associations
-
-In some cases, you will want to allow a front-end to decide whether to include associated
-content or not. You can achieve this easily by making an association *optional*.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
- has_many :comments, :optional => true
-
- # ...
-end
-
-
-If an association is optional, it will not be included unless the request asks for it
-with an +including+ parameter. The +including+ parameter is a comma-separated list of
-optional associations to include. If the +including+ parameter includes an association
-you did not specify in your serializer, it will receive a +401 Forbidden+ response.
-
h3. Overriding the Defaults
h4. Authorization Scope
@@ -500,24 +481,6 @@ which allows you to define a dynamic authorization scope based on the current re
WARNING: If you use different objects as authorization scopes, make sure that they all implement whatever interface you use in your serializers to control what the outputted JSON looks like.
-h4. Parameter to Specify Included Optional Associations
-
-In most cases, you should be able to use the default +including+ parameter to specify
-which optional associations to include. If you are already using that parameter name or
-want to reserve it for some reason, you can specify a different name by using the
-+serialization_includes_param+ class method.
-
-
-class PostsController < ApplicationController
- serialization_includes_param :associations_to_include
-end
-
-
-You can also implement a +serialization_includes+ instance method, which should return an
-Array of optional includes.
-
-WARNING: If you implement +serialization_includes+ and return an invalid association, your user will receive a +401 Forbidden+ exception.
-
h3. Using Serializers Outside of a Request
The serialization API encapsulates the concern of generating a JSON representation of
--
cgit v1.2.3
From 0e7443060b298d080292b18a5888aaf554cce344 Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Thu, 24 Nov 2011 10:33:04 +1100
Subject: Add step to getting_started to install JS Runtime.
abstrakt on #rubyonrails found that the guide, when followed step by step,
does fails at the 'rails server' command due to a lacking JS runtime.
---
railties/guides/source/getting_started.textile | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index fde83ae730..55415dd41b 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -250,6 +250,18 @@ $ rails --version
If it says something like "Rails 3.1.1" you are ready to continue.
+h5. Installing a JavaScript Runtime
+
+By default, Rails requires a JavaScript interpreter to compile CoffeeScript to JavaScript.
+
+You can install one by running:
+
+
+# gem install therubyracer
+
+
+Or investigate the list of alternatives give by "ExecJS":https://github.com/sstephenson/execjs.
+
h4. Creating the Blog Application
To begin, open a terminal, navigate to a folder where you have rights to create
--
cgit v1.2.3
From ef38c3089e1269e2b315aff503e61c0b23c95f00 Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Thu, 24 Nov 2011 10:59:29 +1100
Subject: Move JS runtime instructions to where the error would be encountered,
remove gem install.
---
railties/guides/source/getting_started.textile | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 55415dd41b..5774eba5ae 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -250,18 +250,6 @@ $ rails --version
If it says something like "Rails 3.1.1" you are ready to continue.
-h5. Installing a JavaScript Runtime
-
-By default, Rails requires a JavaScript interpreter to compile CoffeeScript to JavaScript.
-
-You can install one by running:
-
-
-# gem install therubyracer
-
-
-Or investigate the list of alternatives give by "ExecJS":https://github.com/sstephenson/execjs.
-
h4. Creating the Blog Application
To begin, open a terminal, navigate to a folder where you have rights to create
@@ -462,6 +450,12 @@ start a web server on your development machine. You can do this by running:
$ rails server
+TIP: Some environments require that you install a JavaScript runtime to compile
+CoffeeScript to JavaScript and will give you an +execjs+ error the first time
+you run +rails server+. +therubyracer+ and +therubyrhino+ are commonly used
+runtimes for Ruby and JRuby respectively. You can also investigate a list
+of runtimes at "ExecJS":https://github.com/sstephenson/execjs.
+
This will fire up an instance of the WEBrick web server by default (Rails can
also use several other web servers). To see your application in action, open a
browser window and navigate to "http://localhost:3000":http://localhost:3000.
--
cgit v1.2.3
From 510502ee3abfc8feacdf82868013f2f81676c8ff Mon Sep 17 00:00:00 2001
From: rpq
Date: Wed, 23 Nov 2011 23:23:48 -0500
Subject: comma
---
railties/guides/source/active_support_core_extensions.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index ff6c5f967f..da70f9206d 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -571,7 +571,7 @@ NOTE: Defined in +active_support/core_ext/module/attr_accessor_with_default.rb+.
h5. Internal Attributes
-When you are defining an attribute in a class that is meant to be subclassed name collisions are a risk. That's remarkably important for libraries.
+When you are defining an attribute in a class that is meant to be subclassed, name collisions are a risk. That's remarkably important for libraries.
Active Support defines the macros +attr_internal_reader+, +attr_internal_writer+, and +attr_internal_accessor+. They behave like their Ruby built-in +attr_*+ counterparts, except they name the underlying instance variable in a way that makes collisions less likely.
--
cgit v1.2.3
From 0a4035b12a6c59253cb60f9e3456513c6a6a9d33 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Fri, 25 Nov 2011 19:29:39 +0000
Subject: Revert the serializers API as other alternatives are now also under
discussion
---
railties/guides/source/serializers.textile | 563 -----------------------------
1 file changed, 563 deletions(-)
delete mode 100644 railties/guides/source/serializers.textile
(limited to 'railties/guides')
diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile
deleted file mode 100644
index efc7cbf248..0000000000
--- a/railties/guides/source/serializers.textile
+++ /dev/null
@@ -1,563 +0,0 @@
-h2. Rails Serializers
-
-This guide describes how to use Active Model serializers to build non-trivial JSON services in Rails. By reading this guide, you will learn:
-
-* When to use the built-in Active Model serialization
-* When to use a custom serializer for your models
-* How to use serializers to encapsulate authorization concerns
-* How to create serializer templates to describe the application-wide structure of your serialized JSON
-* How to build resources not backed by a single database table for use with JSON services
-
-This guide covers an intermediate topic and assumes familiarity with Rails conventions. It is suitable for applications that expose a
-JSON API that may return different results based on the authorization status of the user.
-
-endprologue.
-
-h3. Serialization
-
-By default, Active Record objects can serialize themselves into JSON by using the `to_json` method. This method takes a series of additional
-parameter to control which properties and associations Rails should include in the serialized output.
-
-When building a web application that uses JavaScript to retrieve JSON data from the server, this mechanism has historically been the primary
-way that Rails developers prepared their responses. This works great for simple cases, as the logic for serializing an Active Record object
-is neatly encapsulated in Active Record itself.
-
-However, this solution quickly falls apart in the face of serialization requirements based on authorization. For instance, a web service
-may choose to expose additional information about a resource only if the user is entitled to access it. In addition, a JavaScript front-end
-may want information that is not neatly described in terms of serializing a single Active Record object, or in a different format than.
-
-In addition, neither the controller nor the model seems like the correct place for logic that describes how to serialize an model object
-*for the current user*.
-
-Serializers solve these problems by encapsulating serialization in an object designed for this purpose. If the default +to_json+ semantics,
-with at most a few configuration options serve your needs, by all means continue to use the built-in +to_json+. If you find yourself doing
-hash-driven-development in your controllers, juggling authorization logic and other concerns, serializers are for you!
-
-h3. The Most Basic Serializer
-
-A basic serializer is a simple Ruby object named after the model class it is serializing.
-
-
-class PostSerializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def as_json
- { post: { title: @post.name, body: @post.body } }
- end
-end
-
-
-A serializer is initialized with two parameters: the model object it should serialize and an authorization scope. By default, the
-authorization scope is the current user (+current_user+) but you can use a different object if you want. The serializer also
-implements an +as_json+ method, which returns a Hash that will be sent to the JSON encoder.
-
-Rails will transparently use your serializer when you use +render :json+ in your controller.
-
-
-class PostsController < ApplicationController
- def show
- @post = Post.find(params[:id])
- render json: @post
- end
-end
-
-
-Because +respond_with+ uses +render :json+ under the hood for JSON requests, Rails will automatically use your serializer when
-you use +respond_with+ as well.
-
-h4. +serializable_hash+
-
-In general, you will want to implement +serializable_hash+ and +as_json+ to allow serializers to embed associated content
-directly. The easiest way to implement these two methods is to have +as_json+ call +serializable_hash+ and insert the root.
-
-
-class PostSerializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def serializable_hash
- { title: @post.name, body: @post.body }
- end
-
- def as_json
- { post: serializable_hash }
- end
-end
-
-
-h4. Authorization
-
-Let's update our serializer to include the email address of the author of the post, but only if the current user has superuser
-access.
-
-
-class PostSerializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def as_json
- { post: serializable_hash }
- end
-
- def serializable_hash
- hash = post
- hash.merge!(super_data) if super?
- hash
- end
-
-private
- def post
- { title: @post.name, body: @post.body }
- end
-
- def super_data
- { email: @post.email }
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-h4. Testing
-
-One benefit of encapsulating our objects this way is that it becomes extremely straight-forward to test the serialization
-logic in isolation.
-
-
-require "ostruct"
-
-class PostSerializerTest < ActiveSupport::TestCase
- # For now, we use a very simple authorization structure. These tests will need
- # refactoring if we change that.
- plebe = OpenStruct.new(super?: false)
- god = OpenStruct.new(super?: true)
-
- post = OpenStruct.new(title: "Welcome to my blog!", body: "Blah blah blah", email: "tenderlove@gmail.com")
-
- test "a regular user sees just the title and body" do
- json = PostSerializer.new(post, plebe).to_json
- hash = JSON.parse(json)
-
- assert_equal post.title, hash.delete("title")
- assert_equal post.body, hash.delete("body")
- assert_empty hash
- end
-
- test "a superuser sees the title, body and email" do
- json = PostSerializer.new(post, god).to_json
- hash = JSON.parse(json)
-
- assert_equal post.title, hash.delete("title")
- assert_equal post.body, hash.delete("body")
- assert_equal post.email, hash.delete("email")
- assert_empty hash
- end
-end
-
-
-It's important to note that serializer objects define a clear interface specifically for serializing an existing object.
-In this case, the serializer expects to receive a post object with +name+, +body+ and +email+ attributes and an authorization
-scope with a +super?+ method.
-
-By defining a clear interface, it's must easier to ensure that your authorization logic is behaving correctly. In this case,
-the serializer doesn't need to concern itself with how the authorization scope decides whether to set the +super?+ flag, just
-whether it is set. In general, you should document these requirements in your serializer files and programatically via tests.
-The documentation library +YARD+ provides excellent tools for describing this kind of requirement:
-
-
-class PostSerializer
- # @param [~body, ~title, ~email] post the post to serialize
- # @param [~super] scope the authorization scope for this serializer
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- # ...
-end
-
-
-h3. Attribute Sugar
-
-To simplify this process for a number of common cases, Rails provides a default superclass named +ActiveModel::Serializer+
-that you can use to implement your serializers.
-
-For example, you will sometimes want to simply include a number of existing attributes from the source model into the outputted
-JSON. In the above example, the +title+ and +body+ attributes were always included in the JSON. Let's see how to use
-+ActiveModel::Serializer+ to simplify our post serializer.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
-
- def initialize(post, scope)
- @post, @scope = post, scope
- end
-
- def serializable_hash
- hash = attributes
- hash.merge!(super_data) if super?
- hash
- end
-
-private
- def super_data
- { email: @post.email }
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-First, we specified the list of included attributes at the top of the class. This will create an instance method called
-+attributes+ that extracts those attributes from the post model.
-
-NOTE: Internally, +ActiveModel::Serializer+ uses +read_attribute_for_serialization+, which defaults to +read_attribute+, which defaults to +send+. So if you're rolling your own models for use with the serializer, you can use simple Ruby accessors for your attributes if you like.
-
-Next, we use the attributes methood in our +serializable_hash+ method, which allowed us to eliminate the +post+ method we hand-rolled
-earlier. We could also eliminate the +as_json+ method, as +ActiveModel::Serializer+ provides a default +as_json+ method for
-us that calls our +serializable_hash+ method and inserts a root. But we can go a step further!
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-The superclass provides a default +initialize+ method as well as a default +serializable_hash+ method, which uses
-+attributes+. We can call +super+ to get the hash based on the attributes we declared, and then add in any additional
-attributes we want to use.
-
-NOTE: +ActiveModel::Serializer+ will create an accessor matching the name of the current class for the resource you pass in. In this case, because we have defined a PostSerializer, we can access the resource with the +post+ accessor.
-
-h3. Associations
-
-In most JSON APIs, you will want to include associated objects with your serialized object. In this case, let's include
-the comments with the current post.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
- has_many :comments
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-The default +serializable_hash+ method will include the comments as embedded objects inside the post.
-
-
-{
- post: {
- title: "Hello Blog!",
- body: "This is my first post. Isn't it fabulous!",
- comments: [
- {
- title: "Awesome",
- body: "Your first post is great"
- }
- ]
- }
-}
-
-
-Rails uses the same logic to generate embedded serializations as it does when you use +render :json+. In this case,
-because you didn't define a +CommentSerializer+, Rails used the default +as_json+ on your comment object.
-
-If you define a serializer, Rails will automatically instantiate it with the existing authorization scope.
-
-
-class CommentSerializer
- def initialize(comment, scope)
- @comment, @scope = comment, scope
- end
-
- def serializable_hash
- { title: @comment.title }
- end
-
- def as_json
- { comment: serializable_hash }
- end
-end
-
-
-If we define the above comment serializer, the outputted JSON will change to:
-
-
-{
- post: {
- title: "Hello Blog!",
- body: "This is my first post. Isn't it fabulous!",
- comments: [{ title: "Awesome" }]
- }
-}
-
-
-Let's imagine that our comment system allows an administrator to kill a comment, and we only want to allow
-users to see the comments they're entitled to see. By default, +has_many :comments+ will simply use the
-+comments+ accessor on the post object. We can override the +comments+ accessor to limit the comments used
-to just the comments we want to allow for the current user.
-
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title. :body
- has_many :comments
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def comments
- post.comments_for(scope)
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-+ActiveModel::Serializer+ will still embed the comments, but this time it will use just the comments
-for the current user.
-
-NOTE: The logic for deciding which comments a user should see still belongs in the model layer. In general, you should encapsulate concerns that require making direct Active Record queries in scopes or public methods on your models.
-
-h3. Customizing Associations
-
-Not all front-ends expect embedded documents in the same form. In these cases, you can override the
-default +serializable_hash+, and use conveniences provided by +ActiveModel::Serializer+ to avoid having to
-build up the hash manually.
-
-For example, let's say our front-end expects the posts and comments in the following format:
-
-
-{
- post: {
- id: 1
- title: "Hello Blog!",
- body: "This is my first post. Isn't it fabulous!",
- comments: [1,2]
- },
- comments: [
- {
- id: 1
- title: "Awesome",
- body: "Your first post is great"
- },
- {
- id: 2
- title: "Not so awesome",
- body: "Why is it so short!"
- }
- ]
-}
-
-
-We could achieve this with a custom +as_json+ method. We will also need to define a serializer for comments.
-
-
-class CommentSerializer < ActiveModel::Serializer
- attributes :id, :title, :body
-
- # define any logic for dealing with authorization-based attributes here
-end
-
-class PostSerializer < ActiveModel::Serializer
- attributes :title, :body
- has_many :comments
-
- def as_json
- { post: serializable_hash }.merge!(associations)
- end
-
- def serializable_hash
- post_hash = attributes
- post_hash.merge!(association_ids)
- post_hash
- end
-
-private
- def attributes
- hash = super
- hash.merge!(email: post.email) if super?
- hash
- end
-
- def comments
- post.comments_for(scope)
- end
-
- def super?
- @scope.superuser?
- end
-end
-
-
-Here, we used two convenience methods: +associations+ and +association_ids+. The first,
-+associations+, creates a hash of all of the define associations, using their defined
-serializers. The second, +association_ids+, generates a hash whose key is the association
-name and whose value is an Array of the association's keys.
-
-The +association_ids+ helper will use the overridden version of the association, so in
-this case, +association_ids+ will only include the ids of the comments provided by the
-+comments+ method.
-
-h3. Special Association Serializers
-
-So far, associations defined in serializers use either the +as_json+ method on the model
-or the defined serializer for the association type. Sometimes, you may want to serialize
-associated models differently when they are requested as part of another resource than
-when they are requested on their own.
-
-For instance, we might want to provide the full comment when it is requested directly,
-but only its title when requested as part of the post. To achieve this, you can define
-a serializer for associated objects nested inside the main serializer.
-
-
-class PostSerializer < ActiveModel::Serializer
- class CommentSerializer < ActiveModel::Serializer
- attributes :id, :title
- end
-
- # same as before
- # ...
-end
-
-
-In other words, if a +PostSerializer+ is trying to serialize comments, it will first
-look for +PostSerializer::CommentSerializer+ before falling back to +CommentSerializer+
-and finally +comment.as_json+.
-
-h3. Overriding the Defaults
-
-h4. Authorization Scope
-
-By default, the authorization scope for serializers is +:current_user+. This means
-that when you call +render json: @post+, the controller will automatically call
-its +current_user+ method and pass that along to the serializer's initializer.
-
-If you want to change that behavior, simply use the +serialization_scope+ class
-method.
-
-
-class PostsController < ApplicationController
- serialization_scope :current_app
-end
-
-
-You can also implement an instance method called (no surprise) +serialization_scope+,
-which allows you to define a dynamic authorization scope based on the current request.
-
-WARNING: If you use different objects as authorization scopes, make sure that they all implement whatever interface you use in your serializers to control what the outputted JSON looks like.
-
-h3. Using Serializers Outside of a Request
-
-The serialization API encapsulates the concern of generating a JSON representation of
-a particular model for a particular user. As a result, you should be able to easily use
-serializers, whether you define them yourself or whether you use +ActiveModel::Serializer+
-outside a request.
-
-For instance, if you want to generate the JSON representation of a post for a user outside
-of a request:
-
-
-user = get_user # some logic to get the user in question
-PostSerializer.new(post, user).to_json # reliably generate JSON output
-
-
-If you want to generate JSON for an anonymous user, you should be able to use whatever
-technique you use in your application to generate anonymous users outside of a request.
-Typically, that means creating a new user and not saving it to the database:
-
-
-user = User.new # create a new anonymous user
-PostSerializer.new(post, user).to_json
-
-
-In general, the better you encapsulate your authorization logic, the more easily you
-will be able to use the serializer outside of the context of a request. For instance,
-if you use an authorization library like Cancan, which uses a uniform +user.can?(action, model)+,
-the authorization interface can very easily be replaced by a plain Ruby object for
-testing or usage outside the context of a request.
-
-h3. Collections
-
-So far, we've talked about serializing individual model objects. By default, Rails
-will serialize collections, including when using the +associations+ helper, by
-looping over each element of the collection, calling +serializable_hash+ on the element,
-and then grouping them by their type (using the plural version of their class name
-as the root).
-
-For example, an Array of post objects would serialize as:
-
-
-{
- posts: [
- {
- title: "FIRST POST!",
- body: "It's my first pooooost"
- },
- { title: "Second post!",
- body: "Zomg I made it to my second post"
- }
- ]
-}
-
-
-If you want to change the behavior of serialized Arrays, you need to create
-a custom Array serializer.
-
-
-class ArraySerializer < ActiveModel::ArraySerializer
- def serializable_array
- serializers.map do |serializer|
- serializer.serializable_hash
- end
- end
-
- def as_json
- hash = { root => serializable_array }
- hash.merge!(associations)
- hash
- end
-end
-
-
-When generating embedded associations using the +associations+ helper inside a
-regular serializer, it will create a new ArraySerializer with the
-associated content and call its +serializable_array+ method. In this case, those
-embedded associations will not recursively include associations.
-
-When generating an Array using +render json: posts+, the controller will invoke
-the +as_json+ method, which will include its associations and its root.
--
cgit v1.2.3
From 3f1a4c3415113f2d365eb1a5531757699afec605 Mon Sep 17 00:00:00 2001
From: gregolsen
Date: Sun, 6 Nov 2011 21:42:03 +0200
Subject: beginning_of_week extended in both Time and Date so that to return
week start based on start day that is monday by default
---
railties/guides/source/active_support_core_extensions.textile | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index ff6c5f967f..c6130f4f62 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3039,12 +3039,14 @@ Active Support defines these methods as well for Ruby 1.8.
h6. +beginning_of_week+, +end_of_week+
-The methods +beginning_of_week+ and +end_of_week+ return the dates for the beginning and end of week, assuming weeks start on Monday:
+The methods +beginning_of_week+ and +end_of_week+ receive a symbol with a day name in English (in lowercase, default is :monday) and return the dates for the beginning and end of week, assuming weeks start on day, passed as parameter:
-d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
-d.beginning_of_week # => Mon, 03 May 2010
-d.end_of_week # => Sun, 09 May 2010
+d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
+d.beginning_of_week # => Mon, 03 May 2010
+d.beginning_of_week(:sunday) # => Sun, 02 May 2010
+d.end_of_week # => Sun, 09 May 2010
+d.end_of_week(:sunday) # => Sat, 08 May 2010
+beginning_of_week+ is aliased to +monday+ and +at_beginning_of_week+. +end_of_week+ is aliased to +sunday+ and +at_end_of_week+.
--
cgit v1.2.3
From a5b362df567ed4a0167a83e9b8f00b9f614ac38b Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Fri, 25 Nov 2011 12:01:58 -0800
Subject: some tweaks to PR#3547. [Closes #3547]
---
railties/guides/source/active_support_core_extensions.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index c6130f4f62..09f931050d 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3039,7 +3039,9 @@ Active Support defines these methods as well for Ruby 1.8.
h6. +beginning_of_week+, +end_of_week+
-The methods +beginning_of_week+ and +end_of_week+ receive a symbol with a day name in English (in lowercase, default is :monday) and return the dates for the beginning and end of week, assuming weeks start on day, passed as parameter:
+The methods +beginning_of_week+ and +end_of_week+ return the dates for the
+beginning and end of the week, respectively. Weeks are assumed to start on
+Monday, but that can be changed passing an argument, see examples:
d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
--
cgit v1.2.3
From 1be9830d4d99e2bf56f1cadf74b843f22d66da35 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Fri, 25 Nov 2011 14:29:34 -0800
Subject: add the query to AR::Relation#explain output
Rationale: this is more readable if serveral queries
are involved in one call. Also, it will be possible
to let AR log EXPLAINs automatically in production
mode, where queries are not even around.
---
railties/guides/source/active_record_querying.textile | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index ad12dca7e8..0f1f6eba4c 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1287,6 +1287,7 @@ User.where(:id => 1).joins(:posts).explain
may yield
+EXPLAIN for: SELECT `users`.* FROM `users` INNER JOIN `posts` ON `posts`.`user_id` = `users`.`id` WHERE `users`.`id` = 1
------------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
------------------------------------------------------------------------------------------
@@ -1302,6 +1303,7 @@ Active Record performs a pretty printing that emulates the one of the database
shells. So, the same query running with the PostgreSQL adapter would yield instead
+EXPLAIN for: SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."user_id" = "users"."id" WHERE "users"."id" = 1
QUERY PLAN
------------------------------------------------------------------------------
Nested Loop Left Join (cost=0.00..37.24 rows=8 width=0)
@@ -1324,12 +1326,15 @@ User.where(:id => 1).includes(:posts).explain
yields
+EXPLAIN for: SELECT `users`.* FROM `users` WHERE `users`.`id` = 1
------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
------------------------------------------------------------------------------------
| 1 | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | |
------------------------------------------------------------------------------------
1 row in set (0.00 sec)
+
+EXPLAIN for: SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` IN (1)
-------------------------------------------------------------------------------------
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-------------------------------------------------------------------------------------
--
cgit v1.2.3
From b30b932447d3ae059c0dac2c5bf0a3a79e0fa54e Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Fri, 25 Nov 2011 14:58:43 -0800
Subject: finders guide: adds some pointers to help users interpret the output
of EXPLAIN
---
railties/guides/source/active_record_querying.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 0f1f6eba4c..c4724f182e 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1344,3 +1344,14 @@ EXPLAIN for: SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` IN (1)
under MySQL.
+
+h4. Interpreting EXPLAIN
+
+Interpretation of the output of EXPLAIN is beyond the scope of this guide. The
+following pointers may be helpful:
+
+* SQLite3: "EXPLAIN QUERY PLAN":http://www.sqlite.org/eqp.html
+
+* MySQL: "EXPLAIN Output Format":http://dev.mysql.com/doc/refman/5.6/en/explain-output.html
+
+* PostgreSQL: "Using EXPLAIN":http://www.postgresql.org/docs/current/static/using-explain.html
--
cgit v1.2.3
From 5c2a2ee76e2af591a997b71eec0e35143c07f9e1 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 26 Nov 2011 19:06:53 +0530
Subject: rephrased ef38c3089e1269e2b315aff503e61c0b23c95f00 and mentioned
about OS X and windows usually having a JS runtime
---
railties/guides/source/getting_started.textile | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 5774eba5ae..ca6a404212 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -450,11 +450,7 @@ start a web server on your development machine. You can do this by running:
$ rails server
-TIP: Some environments require that you install a JavaScript runtime to compile
-CoffeeScript to JavaScript and will give you an +execjs+ error the first time
-you run +rails server+. +therubyracer+ and +therubyrhino+ are commonly used
-runtimes for Ruby and JRuby respectively. You can also investigate a list
-of runtimes at "ExecJS":https://github.com/sstephenson/execjs.
+TIP: Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an +execjs+ error. Usually Mac OS X and Windows come with a JavaScript runtime installed. +therubyracer+ and +therubyrhino+ are the commonly used runtimes for Ruby and JRuby respectively. You can also investigate a list of runtimes at "ExecJS":https://github.com/sstephenson/execjs.
This will fire up an instance of the WEBrick web server by default (Rails can
also use several other web servers). To see your application in action, open a
--
cgit v1.2.3
From 99ff8fdab54e1a3d9377d114d8f9e3e45e6824ac Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 26 Nov 2011 22:04:20 +0530
Subject: minor doc changes
---
railties/guides/source/active_support_core_extensions.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index d601e9ea29..6c95a01a0e 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3041,7 +3041,7 @@ h6. +beginning_of_week+, +end_of_week+
The methods +beginning_of_week+ and +end_of_week+ return the dates for the
beginning and end of the week, respectively. Weeks are assumed to start on
-Monday, but that can be changed passing an argument, see examples:
+Monday, but that can be changed passing an argument.
d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
--
cgit v1.2.3
From 8135e5e6998f99bec56df365f1a580bae4bf1cb1 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 26 Nov 2011 22:04:56 +0530
Subject: s/end_on_week/end_of_week
---
railties/guides/source/active_support_core_extensions.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 6c95a01a0e..370ab311c2 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3277,7 +3277,7 @@ The class +DateTime+ is a subclass of +Date+ so by loading +active_support/core_
yesterday
tomorrow
beginning_of_week (monday, at_beginning_of_week)
-end_on_week (at_end_of_week)
+end_of_week (at_end_of_week)
weeks_ago
prev_week
next_week
@@ -3451,7 +3451,7 @@ since (in)
beginning_of_day (midnight, at_midnight, at_beginning_of_day)
end_of_day
beginning_of_week (monday, at_beginning_of_week)
-end_on_week (at_end_of_week)
+end_of_week (at_end_of_week)
weeks_ago
prev_week
next_week
--
cgit v1.2.3
From fc20d6b6815032935f02b53b4b928cd514ed66ac Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sat, 26 Nov 2011 22:38:58 +0530
Subject: Let's say this 3.1.3 instead of 3.1.1 in docs
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index ca6a404212..fe43c9db36 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -248,7 +248,7 @@ the following:
$ rails --version
-If it says something like "Rails 3.1.1" you are ready to continue.
+If it says something like "Rails 3.1.3" you are ready to continue.
h4. Creating the Blog Application
--
cgit v1.2.3
From a8f2860d0e7db86c61bb70935006100b04667ab1 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 26 Nov 2011 22:26:52 +0530
Subject: Convert aliases monday and sunday to methods
A recent change to beginning_of_week and end_of_week added an argument
that can be used to specify the week's starting day as a symbol. Now
these methods were aliased as monday and sunday respectively which as a
consequence of the argument addition, made calls like obj.monday(:sunday)
possible. This commit makes them methods on their own.
---
railties/guides/source/active_support_core_extensions.textile | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 370ab311c2..37719934a6 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3051,7 +3051,7 @@ d.end_of_week # => Sun, 09 May 2010
d.end_of_week(:sunday) # => Sat, 08 May 2010
-+beginning_of_week+ is aliased to +monday+ and +at_beginning_of_week+. +end_of_week+ is aliased to +sunday+ and +at_end_of_week+.
++beginning_of_week+ is aliased to +at_beginning_of_week+ and +end_of_week+ is aliased to +at_end_of_week+.
h6. +prev_week+, +next_week+
@@ -3276,8 +3276,10 @@ The class +DateTime+ is a subclass of +Date+ so by loading +active_support/core_
yesterday
tomorrow
-beginning_of_week (monday, at_beginning_of_week)
+beginning_of_week (at_beginning_of_week)
end_of_week (at_end_of_week)
+monday
+sunday
weeks_ago
prev_week
next_week
@@ -3450,8 +3452,9 @@ ago
since (in)
beginning_of_day (midnight, at_midnight, at_beginning_of_day)
end_of_day
-beginning_of_week (monday, at_beginning_of_week)
+beginning_of_week (at_beginning_of_week)
end_of_week (at_end_of_week)
+monday
weeks_ago
prev_week
next_week
--
cgit v1.2.3
From 80ac4dc6d0632937ccf61b38bc15fc2f6e27b18b Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 26 Nov 2011 23:10:42 +0530
Subject: Adds Time#sunday method
---
railties/guides/source/active_support_core_extensions.textile | 1 +
1 file changed, 1 insertion(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 37719934a6..a58be1f309 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3455,6 +3455,7 @@ end_of_day
beginning_of_week (at_beginning_of_week)
end_of_week (at_end_of_week)
monday
+sunday
weeks_ago
prev_week
next_week
--
cgit v1.2.3
From ab854db6493bd684e9db1dc1d6461b11dfbb2e58 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 26 Nov 2011 23:43:52 +0530
Subject: documenting monday and sunday methods
---
railties/guides/source/active_support_core_extensions.textile | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index a58be1f309..2dee440b3b 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3053,6 +3053,17 @@ d.end_of_week(:sunday) # => Sat, 08 May 2010
+beginning_of_week+ is aliased to +at_beginning_of_week+ and +end_of_week+ is aliased to +at_end_of_week+.
+h6. +monday+, +sunday+
+
+The methods +monday+ and +sunday+ return the dates for the beginning and
+end of the week, respectively. Weeks are assumed to start on Monday.
+
+
+d = Date.new(2010, 5, 8) # => Sat, 08 May 2010
+d.monday # => Mon, 03 May 2010
+d.sunday # => Sun, 09 May 2010
+
+
h6. +prev_week+, +next_week+
The method +next_week+ receives a symbol with a day name in English (in lowercase, default is +:monday+) and it returns the date corresponding to that day:
--
cgit v1.2.3
From 0ce64ba9aa93c01ee69c45493ad8090e76f95ff4 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 27 Nov 2011 12:34:14 +0530
Subject: Documentation about config.log_level config options
---
railties/guides/source/configuring.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index 809948b41e..beb623757b 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -88,6 +88,8 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is
* +config.log_level+ defines the verbosity of the Rails logger. This option defaults to +:debug+ for all modes except production, where it defaults to +:info+.
+* +config.log_tags+ accepts a list of methods that respond to +request+ object. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications.
+
* +config.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby +Logger+ class. Defaults to an instance of +ActiveSupport::BufferedLogger+, with auto flushing off in production mode.
* +config.middleware+ allows you to configure the application's middleware. This is covered in depth in the "Configuring Middleware":#configuring-middleware section below.
--
cgit v1.2.3
From 28e3935360c9392685c4954791cc320ed02e15c0 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Sun, 27 Nov 2011 12:53:08 +0530
Subject: [Docs] Adding RequestId middleware in configuring middleware
---
railties/guides/source/configuring.textile | 1 +
1 file changed, 1 insertion(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index beb623757b..d91011c370 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -190,6 +190,7 @@ Every Rails application comes with a standard set of middleware which it uses in
* +Rack::Runtime+ sets an +X-Runtime+ header, containing the time (in seconds) taken to execute the request.
* +Rails::Rack::Logger+ notifies the logs that the request has began. After request is complete, flushes all the logs.
* +ActionDispatch::ShowExceptions+ rescues any exception returned by the application and renders nice exception pages if the request is local or if +config.consider_all_requests_local+ is set to +true+. If +config.action_dispatch.show_exceptions+ is set to +false+, exceptions will be raised regardless.
+* +ActionDispatch::RequestId+ makes a unique X-Request-Id header available to the response and enables the +ActionDispatch::Request#uuid+ method.
* +ActionDispatch::RemoteIp+ checks for IP spoofing attacks. Configurable with the +config.action_dispatch.ip_spoofing_check+ and +config.action_dispatch.trusted_proxies+ settings.
* +Rack::Sendfile+ intercepts responses whose body is being served from a file and replaces it with a server specific X-Sendfile header. Configurable with +config.action_dispatch.x_sendfile_header+.
* +ActionDispatch::Callbacks+ runs the prepare callbacks before serving the request.
--
cgit v1.2.3
From 9cf285599c1e99736f5dd9d01f986c19dcf3d4da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadas=20Tamo=C5=A1auskas?=
Date: Sun, 27 Nov 2011 12:44:14 +0000
Subject: Update Object#in? description for
https://github.com/rails/rails/pull/3767
---
railties/guides/source/active_support_core_extensions.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index d601e9ea29..c1046a3b63 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -440,14 +440,16 @@ NOTE: Defined in +active_support/core_ext/kernel/reporting.rb+.
h4. +in?+
-The predicate +in?+ tests if an object is included in another object. An +ArgumentError+ exception will be raised if the argument passed does not respond to +include?+.
+The predicate +in?+ tests if an object is included in another object or a list of objects. An +ArgumentError+ exception will be raised if a single argument is passed and it does not respond to +include?+.
Examples of +in?+:
+1.in?(1,2) # => true
1.in?([1,2]) # => true
"lo".in?("hello") # => true
25.in?(30..50) # => false
+1.in?(1) # => ArgumentError
NOTE: Defined in +active_support/core_ext/object/inclusion.rb+.
--
cgit v1.2.3
From 2f428a6245a18017c7942f8fef3da4a85bec8cc5 Mon Sep 17 00:00:00 2001
From: Tim Reischmann
Date: Mon, 28 Nov 2011 09:27:42 +0100
Subject: fixed typo in getting started form_for for comments
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index fe43c9db36..3ff6603a4c 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1297,7 +1297,7 @@ So first, we'll wire up the Post show template
Add a comment:
-<%= form_for([@post, @post.comments.build]) do |f| %>
+<%= form_for([@post, @post.comment.build]) do |f| %>
<%= f.label :commenter %>
<%= f.text_field :commenter %>
--
cgit v1.2.3
From e7dff9c1f1e3e8a73c1b5bc5fd4263126813489c Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Mon, 28 Nov 2011 14:10:23 +0530
Subject: Revert "fixed typo in getting started form_for for comments"
This reverts commit 2f428a6245a18017c7942f8fef3da4a85bec8cc5.
See comments here 2f428a6245a18017c7942f8fef3da4a85bec8cc5
---
railties/guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 3ff6603a4c..fe43c9db36 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1297,7 +1297,7 @@ So first, we'll wire up the Post show template
Add a comment:
-<%= form_for([@post, @post.comment.build]) do |f| %>
+<%= form_for([@post, @post.comments.build]) do |f| %>
<%= f.label :commenter %>
<%= f.text_field :commenter %>
--
cgit v1.2.3
From 6d05c793cafe79860bcbb469d6c46c83c531ab34 Mon Sep 17 00:00:00 2001
From: Rodrigo Rosenfeld Rosas
Date: Mon, 28 Nov 2011 13:15:07 -0200
Subject: Update information about foreign key plugins support in the guides
There is not "a number" of up-to-date maintained plugins for dealing with foreign keys.
The foreign_key_migrations does not have any update since 2009 and is also about to be removed:
Extracted from http://www.harukizaemon.com/2009/09/plugins-grab-em-while-theyre-stale.html,
referenced in the plugin reference of the old guide version:
"And so it is that I will very shortly (within the next month) delete most of the plugins from
my GitHub account (harukizaemon)"
---
railties/guides/source/migrations.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 5b52a93853..c63f2aa119 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -670,4 +670,4 @@ The Active Record way claims that intelligence belongs in your models, not in th
Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level, these cannot guarantee referential integrity and so some people augment them with foreign key constraints.
-Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. There are also a number of plugins such as "foreign_key_migrations":https://github.com/harukizaemon/redhillonrails/tree/master/foreign_key_migrations/ which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
+Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. You could also use some plugin like "foreigner":https://github.com/matthuhiggins/foreigner which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
--
cgit v1.2.3
From 493cf44682c19bd69eb2463d260c3bf29c7a23d7 Mon Sep 17 00:00:00 2001
From: Sergey Parizhskiy
Date: Mon, 28 Nov 2011 17:33:01 +0200
Subject: completed documentation for the rails server command
---
railties/guides/source/command_line.textile | 2 ++
1 file changed, 2 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index 3f8643eca3..a26a139baf 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -81,6 +81,8 @@ The server can be run on a different port using the +-p+ option. The default dev
$ rails server -e production -p 4000
+The +-b+ option binds Rails to the specified ip, by default it is 0.0.0.0. You can run a server as a daemon by passing a +-d+ option. Use +-h+ or +--help+ option to get a list of all possible options that can be passed to the +rails server+ command.
+
h4. +rails generate+
The +rails generate+ command uses templates to create a whole lot of things. Running +rails generate+ by itself gives a list of available generators:
--
cgit v1.2.3
From afa31cf327893d79826e0a7d5a8667a44213c161 Mon Sep 17 00:00:00 2001
From: Sergey Parizhskiy
Date: Mon, 28 Nov 2011 17:40:14 +0200
Subject: there is no need to repeat about possibility of using -h option to
get full help
---
railties/guides/source/command_line.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index a26a139baf..9284a542f3 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -81,7 +81,7 @@ The server can be run on a different port using the +-p+ option. The default dev
$ rails server -e production -p 4000
-The +-b+ option binds Rails to the specified ip, by default it is 0.0.0.0. You can run a server as a daemon by passing a +-d+ option. Use +-h+ or +--help+ option to get a list of all possible options that can be passed to the +rails server+ command.
+The +-b+ option binds Rails to the specified ip, by default it is 0.0.0.0. You can run a server as a daemon by passing a +-d+ option.
h4. +rails generate+
--
cgit v1.2.3
From 331080a14fea1525e10258528a327390b7199a53 Mon Sep 17 00:00:00 2001
From: Vasiliy Ermolovich
Date: Mon, 28 Nov 2011 20:37:08 +0300
Subject: update guides
---
railties/guides/source/form_helpers.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index 821bb305f6..3658d1361f 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -229,7 +229,7 @@ The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks
There are a few things to note here:
# +@article+ is the actual object being edited.
-# There is a single hash of options. Routing options are passed in the +:url+ hash, HTML options are passed in the +:html+ hash.
+# There is a single hash of options. Routing options are passed in the +:url+ hash, HTML options are passed in the +:html+ hash. Also you can provide a +:namespace+ option for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generate HTML id.
# The +form_for+ method yields a *form builder* object (the +f+ variable).
# Methods to create form controls are called *on* the form builder object +f+
--
cgit v1.2.3
From 0b72a04d0c93b666c23500aefbe4a6a76593cd36 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Tue, 29 Nov 2011 12:28:04 +0000
Subject: Deprecate set_table_name in favour of self.table_name= or defining
your own method.
---
railties/guides/source/active_record_basics.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_basics.textile b/railties/guides/source/active_record_basics.textile
index 66ad7b0255..487f8b70f9 100644
--- a/railties/guides/source/active_record_basics.textile
+++ b/railties/guides/source/active_record_basics.textile
@@ -101,11 +101,11 @@ h3. Overriding the Naming Conventions
What if you need to follow a different naming convention or need to use your Rails application with a legacy database? No problem, you can easily override the default conventions.
-You can use the +ActiveRecord::Base.set_table_name+ method to specify the table name that should be used:
+You can use the +ActiveRecord::Base.table_name=+ method to specify the table name that should be used:
class Product < ActiveRecord::Base
- set_table_name "PRODUCT"
+ self.table_name = "PRODUCT"
end
--
cgit v1.2.3
From a382d60f6abc94b6a965525872f858e48abc00de Mon Sep 17 00:00:00 2001
From: Bogdan Gusiev
Date: Wed, 30 Nov 2011 11:03:00 +0200
Subject: ActiveRecord::Relation#pluck method
---
railties/guides/source/active_record_querying.textile | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index c4724f182e..073f7c143d 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1146,6 +1146,15 @@ h3. +select_all+
Client.connection.select_all("SELECT * FROM clients WHERE id = '1'")
+h3. +pluck+
+
+pluck can be used to query single column from table under model. It accepts column name as argument and returns Array of values of the specified column with corresponding data type.
+
+
+Client.where(:active => true).pluck(:id) # SELECT id FROM clients WHERE clients.active
+Client.uniq.pluck(:role) # SELECT DISTINCT role FROM clients
+
+
h3. Existence of Objects
If you simply want to check for the existence of the object there's a method called +exists?+. This method will query the database using the same query as +find+, but instead of returning an object or collection of objects it will return either +true+ or +false+.
--
cgit v1.2.3
From a72839bc9dc5fb3d56e79f7dc7f85975550d6fde Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 1 Dec 2011 01:06:24 +0530
Subject: minor typo fix
---
railties/guides/source/form_helpers.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index 3658d1361f..64eb2d8f36 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -229,7 +229,7 @@ The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks
There are a few things to note here:
# +@article+ is the actual object being edited.
-# There is a single hash of options. Routing options are passed in the +:url+ hash, HTML options are passed in the +:html+ hash. Also you can provide a +:namespace+ option for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generate HTML id.
+# There is a single hash of options. Routing options are passed in the +:url+ hash, HTML options are passed in the +:html+ hash. Also you can provide a +:namespace+ option for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generated HTML id.
# The +form_for+ method yields a *form builder* object (the +f+ variable).
# Methods to create form controls are called *on* the form builder object +f+
--
cgit v1.2.3
From cbeeaa6ea000d7a6e6ae90de5b6dc756d15240ab Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 1 Dec 2011 01:23:19 +0530
Subject: expand on pluck docs
---
.../guides/source/active_record_querying.textile | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
(limited to 'railties/guides')
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 073f7c143d..352f23dc01 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1148,11 +1148,26 @@ Client.connection.select_all("SELECT * FROM clients WHERE id = '1'")
h3. +pluck+
-pluck can be used to query single column from table under model. It accepts column name as argument and returns Array of values of the specified column with corresponding data type.
+pluck can be used to query a single column from the underlying table of a model. It accepts a column name as argument and returns an array of values of the specified column with the corresponding data type.
-Client.where(:active => true).pluck(:id) # SELECT id FROM clients WHERE clients.active
-Client.uniq.pluck(:role) # SELECT DISTINCT role FROM clients
+Client.where(:active => true).pluck(:id)
+# SELECT id FROM clients WHERE active = 1
+
+Client.uniq.pluck(:role)
+# SELECT DISTINCT role FROM clients
+
+
++pluck+ makes it possible to replace code like
+
+
+Client.select(:id).map { |c| c.id }
+
+
+with
+
+
+Client.pluck(:id)
h3. Existence of Objects
--
cgit v1.2.3