From c17254319b7fadb789cde24d1e72a233a33e4ac7 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 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)>(.*?)}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)>(.*?)}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 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 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 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 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 %> +

This guide documents the asset pipeline.

+<% end %>

Extending Rails

diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb index 5dcac8e74c..5f8ee57517 100644 --- a/railties/guides/source/layout.html.erb +++ b/railties/guides/source/layout.html.erb @@ -5,7 +5,7 @@ -<%= yield(:page_title) || 'Ruby on Rails guides' %> +<%= yield(:page_title) || 'Ruby on Rails Guides' %> @@ -71,6 +71,7 @@
Configuring Rails Applications
Rails Command Line Tools and Rake Tasks
Caching with Rails
+
Asset Pipeline
Extending Rails
The Basics of Creating Rails Plugins
-- 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 @@
Ruby on Rails Guides Guidelines
Release Notes
+
Ruby on Rails 3.1 Release Notes
Ruby on Rails 3.0 Release Notes
Ruby on Rails 2.3 Release Notes
Ruby on Rails 2.2 Release Notes
-- 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