From e05e9979075b37342b7c88e557dbffd672b2086a Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Wed, 9 Mar 2011 10:58:18 +0100 Subject: Add a note to discourage users from using presence validators with allow_(nil|blank) --- railties/guides/source/active_record_validations_callbacks.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 58a184a48e..2301d6715d 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -463,9 +463,11 @@ h3. Common Validation Options There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which are discussed later in "Conditional Validation":#conditional-validation. +TIP: Note that +allow_nil+ and +allow_blank+ will be ignored when using the presence validator. Please use the length validator if you want to validate if something is a specific length but allows for +nil+ values. + h4. +:allow_nil+ -The +:allow_nil+ option skips the validation when the value being validated is +nil+. Using +:allow_nil+ with +validates_presence_of+ allows for +nil+, but any other +blank?+ value will still be rejected. +The +:allow_nil+ option skips the validation when the value being validated is +nil+. class Coffee < ActiveRecord::Base -- cgit v1.2.3 From 6fba542f4487bd825203ea5b14bf038fe722709b Mon Sep 17 00:00:00 2001 From: David Aaron Fendley Date: Wed, 9 Mar 2011 18:06:50 -0600 Subject: Added note re: functional tests and HTTP methods. --- railties/guides/source/testing.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index a75cedbdc1..f4111269ba 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -500,6 +500,8 @@ If you're familiar with the HTTP protocol, you'll know that +get+ is a type of r All of request types are methods that you can use, however, you'll probably end up using the first two more often than the others. +NOTE: Functional tests do not verify whether the specified request type should be be accepted by the action. Request types in this context exist to make your tests more descriptive. + h4. The Four Hashes of the Apocalypse After a request has been made by using one of the 5 methods (+get+, +post+, etc.) and processed, you will have 4 Hash objects ready for use: -- cgit v1.2.3 From 439ccdc3cf2aa46e22a8dfb7debcee073127df86 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 10 Mar 2011 19:58:55 +0530 Subject: update plugin urls to reflect official maintainers --- railties/guides/source/3_0_release_notes.textile | 4 ++-- railties/guides/source/active_record_validations_callbacks.textile | 2 +- railties/guides/source/debugging_rails_applications.textile | 2 +- railties/guides/source/form_helpers.textile | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 001f458fd9..f75b245ed8 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -59,12 +59,12 @@ The +config.gem+ method is gone and has been replaced by using +bundler+ and a + h4. Upgrade Process -To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/rails/rails_upgrade has been created to automate part of it. +To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/jm/rails_upgrade has been created to automate part of it. Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following: -$ ruby script/plugin install git://github.com/rails/rails_upgrade.git +$ ruby script/plugin install git://github.com/jm/rails_upgrade.git You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 2301d6715d..bfb06a9cd5 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -744,7 +744,7 @@ Rails maintains an official plugin that provides helpers to display the error me h4. Installing as a plugin -$ rails plugin install git://github.com/rails/dynamic_form.git +$ rails plugin install git://github.com/joelmoss/dynamic_form.git h4 Installing as a Gem diff --git a/railties/guides/source/debugging_rails_applications.textile b/railties/guides/source/debugging_rails_applications.textile index 67e17056e5..045b8823ca 100644 --- a/railties/guides/source/debugging_rails_applications.textile +++ b/railties/guides/source/debugging_rails_applications.textile @@ -686,7 +686,7 @@ There are some Rails plugins to help you to find errors and debug your applicati * "Query Trace":https://github.com/ntalbott/query_trace/tree/master: Adds query origin tracing to your logs. * "Query Stats":https://github.com/dan-manges/query_stats/tree/master: A Rails plugin to track database queries. * "Query Reviewer":http://code.google.com/p/query-reviewer/: This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed. -* "Exception Notifier":https://github.com/rails/exception_notification/tree/master: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. +* "Exception Notifier":https://github.com/smartinez87/exception_notification/tree/master: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. * "Exception Logger":https://github.com/defunkt/exception_logger/tree/master: Logs your Rails exceptions in the database and provides a funky web interface to manage them. h3. References diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 0cfc005f80..1f21c27ae6 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -475,7 +475,7 @@ To leverage time zone support in Rails, you have to ask your users what time zon There is also +time_zone_options_for_select+ helper for a more manual (therefore more customizable) way of doing this. Read the API documentation to learn about the possible arguments for these two methods. -Rails _used_ to have a +country_select+ helper for choosing countries, but this has been extracted to the "country_select plugin":https://github.com/rails/country_select/tree/master. When using this, be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from Rails). +Rails _used_ to have a +country_select+ helper for choosing countries, but this has been extracted to the "country_select plugin":https://github.com/chrislerum/country_select. When using this, be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from Rails). h3. Using Date and Time Form Helpers -- cgit v1.2.3 From ee7c48678f443ed7fb77fe97042f7a698e359df9 Mon Sep 17 00:00:00 2001 From: Mike Gehard Date: Thu, 10 Mar 2011 10:08:30 -0500 Subject: Minor formatting changes and remove a comment --- railties/guides/source/plugins.textile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index daca50ee9e..2d9821e627 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -45,9 +45,9 @@ as a gem. This tutorial will begin to bridge that gap by demonstrating how to c "Enginex gem":http://www.github.com/josevalim/enginex. - gem install enginex - enginex --help - enginex yaffle +$ gem install enginex +$ enginex --help +$ enginex yaffle This command will create a new directory named "yaffle" within the current directory. @@ -401,7 +401,9 @@ h3. Publishing your Gem Gem plugins in progress can be easily be shared from any Git repository. To share the Yaffle gem with others, simply commit the code to a Git repository (like Github) and add a line to the Gemfile of the any application: -gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git' + +gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git' + After running +bundle install+, your gem functionality will be available to the application. @@ -450,8 +452,6 @@ Once your comments are good to go, navigate to your plugin directory and run: $ rake rdoc -!!!!!!!!!!!!!! Make sure these still make sense. Add any references that you see fit. !!!!!!!!!!!!! - h4. References * "Developing a RubyGem using Bundler":https://github.com/radar/guides/blob/master/gem-development.md @@ -462,6 +462,7 @@ h4. References h3. Changelog +* March 10, 2011: Minor formatting tweaks. * February 13, 2011: Get guide in synch with Rails 3.0.3. Remove information not compatible with Rails 3. Send reader elsewhere for information that is covered elsewhere. * April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -- cgit v1.2.3 From c540b3544100a29d3d34ada220c175dbd70bab2f Mon Sep 17 00:00:00 2001 From: Lars Smit Date: Sun, 13 Mar 2011 09:07:23 +0100 Subject: Removed double texts --- .../guides/source/contributing_to_ruby_on_rails.textile | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 4ba01a2a8f..846a25d6d2 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -364,19 +364,6 @@ Please make sure the patch does not introduce whitespace errors: $ git apply --whitespace=error-all mynew_patch.diff -You can check your patches by applying your patch to an different dedicated branch: - - -$ git checkout -b testing_branch -$ git apply --check my_new_patch.diff - - -You can make sure your patches don't add any whitespace by applying it yourself using the --whitespace=error-all option. Make sure you are on your dedicated test branche and: - - -$ git apply --whitespace=error-all mynew_patch.diff - - h4. Create a Lighthouse Ticket -- cgit v1.2.3 From de5e41f855a8d715d99eec6195f9b31cc4048b99 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 14 Mar 2011 21:59:58 +0100 Subject: move the tips about :allow_(nil|blank) near their explanations, also no need to say these are options for all validators if they are not --- .../guides/source/active_record_validations_callbacks.textile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index bfb06a9cd5..e5349d546c 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -461,9 +461,7 @@ The block receives the model, the attribute's name and the attribute's value. Yo h3. Common Validation Options -There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which are discussed later in "Conditional Validation":#conditional-validation. - -TIP: Note that +allow_nil+ and +allow_blank+ will be ignored when using the presence validator. Please use the length validator if you want to validate if something is a specific length but allows for +nil+ values. +These are common validation options: h4. +:allow_nil+ @@ -476,6 +474,8 @@ class Coffee < ActiveRecord::Base end +TIP: +:allow_nil+ is ignored by the presence validator. + h4. +:allow_blank+ The +:allow_blank+ option is similar to the +:allow_nil+ option. This option will let validation pass if the attribute's value is +blank?+, like +nil+ or an empty string for example. @@ -489,6 +489,8 @@ Topic.create("title" => "").valid? # => true Topic.create("title" => nil).valid? # => true +TIP: +:allow_blank+ is ignored by the presence validator. + h4. +:message+ As you've already seen, the +:message+ option lets you specify the message that will be added to the +errors+ collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper. -- cgit v1.2.3 From a0826cceea8d181cc28046929c9025147f9325af Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 14 Mar 2011 22:06:27 +0100 Subject: be be -> be --- railties/guides/source/testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index f4111269ba..4ebdb3edf6 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -500,7 +500,7 @@ If you're familiar with the HTTP protocol, you'll know that +get+ is a type of r All of request types are methods that you can use, however, you'll probably end up using the first two more often than the others. -NOTE: Functional tests do not verify whether the specified request type should be be accepted by the action. Request types in this context exist to make your tests more descriptive. +NOTE: Functional tests do not verify whether the specified request type should be accepted by the action. Request types in this context exist to make your tests more descriptive. h4. The Four Hashes of the Apocalypse -- cgit v1.2.3 From 3edba7189509915c0159e84a7c9be980fae0732f Mon Sep 17 00:00:00 2001 From: Nicolas Cavigneaux Date: Wed, 16 Mar 2011 13:04:39 +0100 Subject: Add link to mailing-list --- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 846a25d6d2..1fcc4fd7e3 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -371,7 +371,7 @@ Now create a ticket with your patch. Go to the "new ticket":http://rails.lightho h4. Get Some Feedback -Now you need to get other people to look at your patch, just as you've looked at other people's patches. You can use the rubyonrails-core mailing list or the #rails-contrib channel on IRC freenode for this. You might also try just talking to Rails developers that you know. +Now you need to get other people to look at your patch, just as you've looked at other people's patches. You can use the "rubyonrails-core mailing list":http://groups.google.com/group/rubyonrails-core/ or the #rails-contrib channel on IRC freenode for this. You might also try just talking to Rails developers that you know. h4. Iterate as Necessary -- cgit v1.2.3 From c24e5548fd372e4d0058ab417230ebc2fa3bebde Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Tue, 22 Mar 2011 12:16:13 +1100 Subject: Querying guide: mention that performing a where on an relation that contains an includes statement will generate a LEFT OUTER JOIN rather than an INNER JOIN or another query --- railties/guides/source/active_record_querying.textile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index ed3968e226..e0fab46db9 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -747,6 +747,20 @@ h4. Specifying Conditions on Eager Loaded Associations Even though Active Record lets you specify conditions on the eager loaded associations just like +joins+, the recommended way is to use "joins":#joining-tables instead. +However if you must do this, you may use +where+ as you would normally. + + +Post.includes(:comments).where("comments.visible", true) + + +This would generate a query which contains a +LEFT OUTER JOIN+ whereas the +joins+ method would generate one using the +INNER JOIN+ function instead. + + + SELECT "posts"."id" AS t0_r0, ... "comments"."updated_at" AS t1_r5 FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE (comments.visible) + + +If in this case there were no comments for any posts, all the posts would still be loaded. By using +joins+ (an INNER JOIN), the join conditions *must* match, otherwise no records will be returned. + h3. Scopes Scoping allows you to specify commonly-used ARel queries which can be referenced as method calls on the association objects or models. With these scopes, you can use every method previously covered such as +where+, +joins+ and +includes+. All scope methods will return an +ActiveRecord::Relation+ object which will allow for further methods (such as other scopes) to be called on it. -- cgit v1.2.3 From 5a44951186b410c3a79685f8aeaa926d93a6aab0 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Tue, 22 Mar 2011 12:16:15 +1100 Subject: Querying guide: mention that performing a where on an relation that contains an includes statement will generate a LEFT OUTER JOIN rather than an INNER JOIN or another query --- railties/guides/source/active_record_querying.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index e0fab46db9..009d541106 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -759,7 +759,9 @@ This would generate a query which contains a +LEFT OUTER JOIN+ whereas the +join SELECT "posts"."id" AS t0_r0, ... "comments"."updated_at" AS t1_r5 FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE (comments.visible) -If in this case there were no comments for any posts, all the posts would still be loaded. By using +joins+ (an INNER JOIN), the join conditions *must* match, otherwise no records will be returned. +If there was no +where+ condition, this would generate the normal set of two queries. + +If, in the case of this +includes+ query, there were no comments for any posts, all the posts would still be loaded. By using +joins+ (an INNER JOIN), the join conditions *must* match, otherwise no records will be returned. h3. Scopes -- cgit v1.2.3 From 137ff0402a05e39c85852b148443750d5d222b66 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 23 Mar 2011 08:33:06 +1100 Subject: Caching guide: Capitalize 'Note' so that it's rendered as a proper note --- railties/guides/source/caching_with_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 1b5ec40d16..297ba2d661 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -65,7 +65,7 @@ end If you want a more complicated expiration scheme, you can use cache sweepers to expire cached objects when things change. This is covered in the section on Sweepers. -Note: Page caching ignores all parameters. For example +/products?page=1+ will be written out to the filesystem as +products.html+ with no reference to the +page+ parameter. Thus, if someone requests +/products?page=2+ later, they will get the cached first page. Be careful when page caching GET parameters in the URL! +NOTE: Page caching ignores all parameters. For example +/products?page=1+ will be written out to the filesystem as +products.html+ with no reference to the +page+ parameter. Thus, if someone requests +/products?page=2+ later, they will get the cached first page. Be careful when page caching GET parameters in the URL! INFO: Page caching runs in an after filter. Thus, invalid requests won't generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job. -- cgit v1.2.3 From ee8ca49414271026575dab70947b446ac6e4b51a Mon Sep 17 00:00:00 2001 From: Dr Nic Williams Date: Tue, 22 Mar 2011 15:11:12 -0700 Subject: Update 'Getting Started on Windows' tip to go to one-click Rails Installer --- 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 e94bdc97b0..0661549644 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -149,7 +149,7 @@ Usually run this as the root user: # gem install rails -TIP. If you're working on Windows, you should be aware that the vast majority of Rails development is done in Unix environments. While Ruby and Rails themselves install easily using for example "Ruby Installer":http://rubyinstaller.org/, the supporting ecosystem often assumes you are able to build C-based rubygems and work in a command window. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows. +TIP. If you're working on Windows, you can quickly install Ruby and Rails with "Rails Installer":http://railsinstaller.org. h4. Creating the Blog Application -- cgit v1.2.3 From a0946692c13b7d1724cbc86731f3611a7f8177d2 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 25 Mar 2011 19:34:45 -0300 Subject: Update AR querying guide with #first! and #last! new methods --- .../guides/source/active_record_querying.textile | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 009d541106..484ba796bd 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -130,6 +130,40 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 Model.last returns +nil+ if no matching record is found. No exception will be raised. +h5. +first!+ + +Model.first! finds the first record matched by the supplied options. For example: + + +client = Client.first! +=> # + + +SQL equivalent of the above is: + + +SELECT * FROM clients LIMIT 1 + + +Model.first! raises +RecordNotFound+ if no matching record is found. + +h5. +last!+ + +Model.last! finds the last record matched by the supplied options. For example: + + +client = Client.last! +=> # + + +SQL equivalent of the above is: + + +SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 + + +Model.last! raises +RecordNotFound+ if no matching record is found. + h4. Retrieving Multiple Objects h5. Using Multiple Primary Keys -- cgit v1.2.3 From 6ee5d9244c418ab51d48bcda444ce50b1ad2a4e7 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 25 Mar 2011 20:07:13 -0300 Subject: impact recent updates to #first! and #last! methods --- railties/guides/source/active_record_querying.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 484ba796bd..2c5d9e67e3 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -76,7 +76,7 @@ Primary operation of Model.find(options) can be summarized as: h4. Retrieving a Single Object -Active Record lets you retrieve a single object using three different ways. +Active Record lets you retrieve a single object using five different ways. h5. Using a Primary Key @@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 h5. +first!+ -Model.first! finds the first record matched by the supplied options. For example: +Model.first! finds the first record. For example: client = Client.first! @@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1 h5. +last!+ -Model.last! finds the last record matched by the supplied options. For example: +Model.last! finds the last record. For example: client = Client.last! -- cgit v1.2.3