diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2015-02-15 12:30:38 +0100 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2015-02-15 19:19:04 +0100 |
commit | 1747c4e2cea811cbf04fccc9f57256c80112d9ce (patch) | |
tree | e0ea6f1b8dedbe206f15b67a9b226618539fc764 | |
parent | 3960908f41ea638556493762937c440761af9a65 (diff) | |
download | rails-1747c4e2cea811cbf04fccc9f57256c80112d9ce.tar.gz rails-1747c4e2cea811cbf04fccc9f57256c80112d9ce.tar.bz2 rails-1747c4e2cea811cbf04fccc9f57256c80112d9ce.zip |
Tiny documentation edits [ci skip]
-rw-r--r-- | actionpack/lib/action_controller/metal/conditional_get.rb | 6 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 10 | ||||
-rw-r--r-- | guides/source/action_view_overview.md | 5 | ||||
-rw-r--r-- | guides/source/active_record_validations.md | 47 | ||||
-rw-r--r-- | guides/source/i18n.md | 5 | ||||
-rw-r--r-- | guides/source/testing.md | 3 |
6 files changed, 41 insertions, 35 deletions
diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb index bc6d336e19..858870d8b8 100644 --- a/actionpack/lib/action_controller/metal/conditional_get.rb +++ b/actionpack/lib/action_controller/metal/conditional_get.rb @@ -215,16 +215,16 @@ module ActionController response.cache_control.replace(:no_cache => true) end - # Cache or yield the block. The cache is suppose to never expire. + # Cache or yield the block. The cache is supposed to never expire. # # You can use this method when you have a HTTP response that never changes, # and the browser and proxies should cache it indefinitely. # - # <tt>public</tt> By default, HTTP responses are private, cached only on the + # * +public+: By default, HTTP responses are private, cached only on the # user's web browser. To allow proxies to cache the response, set +true+ to # indicate that they can serve the cached response to all users. # - # <tt>version</tt> is the version passed as a key for the cache. + # * +version+: the version passed as a key for the cache. def http_cache_forever(public: false, version: 'v1') expires_in 100.years, public: public diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index c63a9d74b3..23201b264a 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -112,10 +112,12 @@ module ActiveModel # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, # <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate # <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message. - # * <tt>:tokenizer</tt> - Specifies a method, proc or string to how to split up the attribute string. - # (e.g. <tt>tokenizer: ->(str) { str.scan(/\w+/) }</tt> or <tt>tokenizer: :word_tokenizer</tt> to count words - # as in above example). Defaults to <tt>->(value) { value.split(//) }</tt> - # which counts individual characters. + # * <tt>:tokenizer</tt> - A method (as a symbol), proc or string to + # specify how to split up the attribute string. (e.g. + # <tt>tokenizer: :word_tokenizer</tt> to call the +word_tokenizer+ method + # or <tt>tokenizer: ->(str) { str.scan(/\w+/) }</tt> to count words as in + # above example). Defaults to <tt>->(value) { value.split(//) }</tt> which + # counts individual characters. # # There is also a list of default options supported by every validator: # +:if+, +:unless+, +:on+ and +:strict+. diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md index fa6d85a3ee..d3a2e15c61 100644 --- a/guides/source/action_view_overview.md +++ b/guides/source/action_view_overview.md @@ -192,7 +192,9 @@ Here, the `_ad_banner.html.erb` and `_footer.html.erb` partials could contain co #### `render` without `partial` and `locals` options -In the above example, `render` takes 2 options: `partial` and `locals`. But if these are the only options you want to pass, you can skip using these options. For example, instead of: +In the above example, `render` takes 2 options: `partial` and `locals`. But if +these are the only options you want to pass, you can skip using these options. +For example, instead of: ```erb <%= render partial: "product", locals: {product: @product} %> @@ -204,7 +206,6 @@ You can also do: <%= render "product", product: @product %> ``` - #### The `as` and `object` options By default `ActionView::Partials::PartialRenderer` has its object in a local variable with the same name as the template. So, given: diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 67cc6a4db3..93f76d3bf7 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -231,9 +231,9 @@ Errors](#working-with-validation-errors) section. ### `errors.details` -To check what validator type was used on invalid attribute, you can use -`errors.details[:attribute]`. It returns array of hashes where under `:error` - key you will find symbol of used validator. +To check which validations failed on an invalid attribute, you can use +`errors.details[:attribute]`. It returns an array of hashes with an `:error` +key to get the symbol of the validator: ```ruby class Person < ActiveRecord::Base @@ -245,7 +245,7 @@ end >> person.errors.details[:name] #=> [{error: :blank}] ``` -Using `details` with custom validators are covered in the [Working with +Using `details` with custom validators is covered in the [Working with Validation Errors](#working-with-validation-errors) section. Validation Helpers @@ -1094,39 +1094,40 @@ Another way to do this is using `[]=` setter ### `errors.details` -You can add validator type to details hash when using `errors.add` method. +You can specify a validator type to the returned error details hash using the +`errors.add` method. ```ruby - class Person < ActiveRecord::Base - def a_method_used_for_validation_purposes - errors.add(:name, :invalid_characters) - end +class Person < ActiveRecord::Base + def a_method_used_for_validation_purposes + errors.add(:name, :invalid_characters) end +end - person = Person.create(name: "!@#") +person = Person.create(name: "!@#") - person.errors.details[:name] - # => [{error: :invalid_characters}] +person.errors.details[:name] +# => [{error: :invalid_characters}] ``` -To improve error details to contain not allowed characters set, you can -pass additional options to `errors.add` method. +To improve the error details to contain the unallowed characters set for instance, +you can pass additional keys to `errors.add`. ```ruby - class Person < ActiveRecord::Base - def a_method_used_for_validation_purposes - errors.add(:name, :invalid_characters, not_allowed: "!@#%*()_-+=") - end +class Person < ActiveRecord::Base + def a_method_used_for_validation_purposes + errors.add(:name, :invalid_characters, not_allowed: "!@#%*()_-+=") end +end - person = Person.create(name: "!@#") +person = Person.create(name: "!@#") - person.errors.details[:name] - # => [{error: :invalid_characters, not_allowed: "!@#%*()_-+="}] +person.errors.details[:name] +# => [{error: :invalid_characters, not_allowed: "!@#%*()_-+="}] ``` -All built in Rails validators populate details hash with corresponding -validator types. +All built in Rails validators populate the details hash with the corresponding +validator type. ### `errors[:base]` diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 8f24c53edb..9b049ea8b8 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -588,7 +588,7 @@ you can look up the `books.index.title` value **inside** `app/views/books/index. NOTE: Automatic translation scoping by partial is only available from the `translate` view helper method. -"Lazy" lookup can also be used in _controllers_: +"Lazy" lookup can also be used in controllers: ```yaml en: @@ -596,7 +596,8 @@ en: create: success: Book created! ``` -which is especially useful for setting flash messages: + +This is useful for setting flash messages for instance: ```ruby class BooksController < ApplicationController diff --git a/guides/source/testing.md b/guides/source/testing.md index 625f366db1..14bc75aa7d 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -545,7 +545,8 @@ NOTE: Functional tests do not verify whether the specified request type is accep ### Testing XHR (AJAX) requests -Enable set `xhr: true` option as an argument to `get/post/patch/put/delete` method: +To test AJAX requests, you can specify the `xhr: true` option to `get`, `post`, +`patch`, `put`, and `delete` methods: ```ruby test "ajax request responds with no layout" do |