Skip to content

Commit

Permalink
Fix Active Record validation error messages markup in guides
Browse files Browse the repository at this point in the history
The other way it was not marking the text as italic, it was showing the
underlines as normal text.

Also fixes some code examples indentation and # => marks in Active Model
and Active Record guides.

[ci skip]
  • Loading branch information
carlosantoniodasilva committed Dec 4, 2012
1 parent 7f39560 commit 129eac0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
36 changes: 18 additions & 18 deletions guides/source/active_model_basics.md
Expand Up @@ -85,9 +85,9 @@ class Person
end

person = Person.new
person.to_model == person #=> true
person.to_key #=> nil
person.to_param #=> nil
person.to_model == person # => true
person.to_key # => nil
person.to_param # => nil
```

### Dirty
Expand Down Expand Up @@ -130,22 +130,22 @@ end

```ruby
person = Person.new
person.changed? #=> false
person.changed? # => false

person.first_name = "First Name"
person.first_name #=> "First Name"
person.first_name # => "First Name"

# returns if any attribute has changed.
person.changed? #=> true
person.changed? # => true

# returns a list of attributes that have changed before saving.
person.changed #=> ["first_name"]
person.changed # => ["first_name"]

# returns a hash of the attributes that have changed with their original values.
person.changed_attributes #=> {"first_name"=>nil}
person.changed_attributes # => {"first_name"=>nil}

# returns a hash of changes, with the attribute names as the keys, and the values will be an array of the old and new value for that field.
person.changes #=> {"first_name"=>[nil, "First Name"]}
person.changes # => {"first_name"=>[nil, "First Name"]}
```

#### Attribute based accessor methods
Expand All @@ -154,23 +154,23 @@ Track whether the particular attribute has been changed or not.

```ruby
# attr_name_changed?
person.first_name #=> "First Name"
person.first_name_changed? #=> true
person.first_name # => "First Name"
person.first_name_changed? # => true
```

Track what was the previous value of the attribute.

```ruby
# attr_name_was accessor
person.first_name_was #=> "First Name"
person.first_name_was # => "First Name"
```

Track both previous and current value of the changed attribute. Returns an array if changed, else returns nil.

```ruby
# attr_name_change
person.first_name_change #=> [nil, "First Name"]
person.last_name_change #=> nil
person.first_name_change # => [nil, "First Name"]
person.last_name_change # => nil
```

### Validations
Expand All @@ -189,12 +189,12 @@ class Person
end

person = Person.new(token: "2b1f325")
person.valid? #=> false
person.valid? # => false
person.name = 'vishnu'
person.email = 'me'
person.valid? #=> false
person.valid? # => false
person.email = 'me@vishnuatrai.com'
person.valid? #=> true
person.valid? # => true
person.token = nil
person.valid? #=> raises ActiveModel::StrictValidationFailed
person.valid? # => raises ActiveModel::StrictValidationFailed
```
42 changes: 21 additions & 21 deletions guides/source/active_record_basics.md
Expand Up @@ -147,50 +147,50 @@ Active Record objects can be created from a hash, a block or have their attribut
For example, given a model `User` with attributes of `name` and `occupation`, the `create` method call will create and save a new record into the database:

```ruby
user = User.create(name: "David", occupation: "Code Artist")
user = User.create(name: "David", occupation: "Code Artist")
```

Using the `new` method, an object can be created without being saved:

```ruby
user = User.new
user.name = "David"
user.occupation = "Code Artist"
user = User.new
user.name = "David"
user.occupation = "Code Artist"
```

A call to `user.save` will commit the record to the database.

Finally, if a block is provided, both `create` and `new` will yield the new object to that block for initialization:

```ruby
user = User.new do |u|
u.name = "David"
u.occupation = "Code Artist"
end
user = User.new do |u|
u.name = "David"
u.occupation = "Code Artist"
end
```

### Read

Active Record provides a rich API for accessing data within a database. Below are a few examples of different data access methods provided by Active Record.

```ruby
# return array with all records
users = User.all
# return array with all records
users = User.all
```

```ruby
# return the first record
user = User.first
# return the first record
user = User.first
```

```ruby
# return the first user named David
david = User.find_by_name('David')
# return the first user named David
david = User.find_by_name('David')
```

```ruby
# find all users named David who are Code Artists and sort by created_at in reverse chronological order
users = User.where(name: 'David', occupation: 'Code Artist').order('created_at DESC')
# find all users named David who are Code Artists and sort by created_at in reverse chronological order
users = User.where(name: 'David', occupation: 'Code Artist').order('created_at DESC')
```

You can learn more about querying an Active Record model in the [Active Record Query Interface](active_record_querying.html) guide.
Expand All @@ -200,18 +200,18 @@ You can learn more about querying an Active Record model in the [Active Record Q
Once an Active Record object has been retrieved, its attributes can be modified and it can be saved to the database.

```ruby
user = User.find_by_name('David')
user.name = 'Dave'
user.save
user = User.find_by_name('David')
user.name = 'Dave'
user.save
```

### Delete

Likewise, once retrieved an Active Record object can be destroyed which removes it from the database.

```ruby
user = User.find_by_name('David')
user.destroy
user = User.find_by_name('David')
user.destroy
```

Validations
Expand Down
2 changes: 1 addition & 1 deletion guides/source/active_record_callbacks.md
Expand Up @@ -200,7 +200,7 @@ Halting Execution

As you start registering new callbacks for your models, they will be queued for execution. This queue will include all your model's validations, the registered callbacks, and the database operation to be executed.

The whole callback chain is wrapped in a transaction. If any <em>before</em> callback method returns exactly `false` or raises an exception, the execution chain gets halted and a ROLLBACK is issued; <em>after</em> callbacks can only accomplish that by raising an exception.
The whole callback chain is wrapped in a transaction. If any _before_ callback method returns exactly `false` or raises an exception, the execution chain gets halted and a ROLLBACK is issued; _after_ callbacks can only accomplish that by raising an exception.

WARNING. Raising an arbitrary exception may break code that expects `save` and its friends not to fail like that. The `ActiveRecord::Rollback` exception is thought precisely to tell Active Record a rollback is going on. That one is internally captured but not reraised.

Expand Down
42 changes: 21 additions & 21 deletions guides/source/active_record_validations.md
Expand Up @@ -264,7 +264,7 @@ class Person < ActiveRecord::Base
end
```

The default error message for this helper is "_must be accepted_".
The default error message for this helper is _"must be accepted"_.

It can receive an `:accept` option, which determines the value that will be
considered acceptance. It defaults to "1" and can be easily changed.
Expand Down Expand Up @@ -293,7 +293,7 @@ This validation will work with all of the association types.
CAUTION: Don't use `validates_associated` on both ends of your associations.
They would call each other in an infinite loop.

The default error message for `validates_associated` is "_is invalid_". Note
The default error message for `validates_associated` is _"is invalid"_. Note
that each associated object will contain its own `errors` collection; errors do
not bubble up to the calling model.

Expand Down Expand Up @@ -328,7 +328,7 @@ class Person < ActiveRecord::Base
end
```

The default error message for this helper is "_doesn't match confirmation_".
The default error message for this helper is _"doesn't match confirmation"_.

### `exclusion`

Expand All @@ -348,7 +348,7 @@ alias called `:within` that you can use for the same purpose, if you'd like to.
This example uses the `:message` option to show how you can include the
attribute's value.

The default error message is "_is reserved_".
The default error message is _"is reserved"_.

### `format`

Expand All @@ -362,7 +362,7 @@ class Product < ActiveRecord::Base
end
```

The default error message is "_is invalid_".
The default error message is _"is invalid"_.

### `inclusion`

Expand All @@ -381,7 +381,7 @@ will be accepted. The `:in` option has an alias called `:within` that you can
use for the same purpose, if you'd like to. The previous example uses the
`:message` option to show how you can include the attribute's value.

The default error message for this helper is "_is not included in the list_".
The default error message for this helper is _"is not included in the list"_.

### `length`

Expand Down Expand Up @@ -471,24 +471,24 @@ Besides `:only_integer`, this helper also accepts the following options to add
constraints to acceptable values:

* `:greater_than` - Specifies the value must be greater than the supplied
value. The default error message for this option is "_must be greater than
%{count}_".
value. The default error message for this option is _"must be greater than
%{count}"_.
* `:greater_than_or_equal_to` - Specifies the value must be greater than or
equal to the supplied value. The default error message for this option is
"_must be greater than or equal to %{count}_".
_"must be greater than or equal to %{count}"_.
* `:equal_to` - Specifies the value must be equal to the supplied value. The
default error message for this option is "_must be equal to %{count}_".
default error message for this option is _"must be equal to %{count}"_.
* `:less_than` - Specifies the value must be less than the supplied value. The
default error message for this option is "_must be less than %{count}_".
default error message for this option is _"must be less than %{count}"_.
* `:less_than_or_equal_to` - Specifies the value must be less than or equal the
supplied value. The default error message for this option is "_must be less
than or equal to %{count}_".
supplied value. The default error message for this option is _"must be less
than or equal to %{count}"_.
* `:odd` - Specifies the value must be an odd number if set to true. The
default error message for this option is "_must be odd_".
default error message for this option is _"must be odd"_.
* `:even` - Specifies the value must be an even number if set to true. The
default error message for this option is "_must be even_".
default error message for this option is _"must be even"_.

The default error message is "_is not a number_".
The default error message is _"is not a number"_.

### `presence`

Expand Down Expand Up @@ -528,7 +528,7 @@ If you validate the presence of an object associated via a `has_one` or
Since `false.blank?` is true, if you want to validate the presence of a boolean
field you should use `validates :field_name, inclusion: { in: [true, false] }`.

The default error message is "_can't be empty_".
The default error message is _"can't be empty"_.

### `uniqueness`

Expand Down Expand Up @@ -570,7 +570,7 @@ end
WARNING. Note that some databases are configured to perform case-insensitive
searches anyway.

The default error message is "_has already been taken_".
The default error message is _"has already been taken"_.

### `validates_with`

Expand Down Expand Up @@ -714,7 +714,7 @@ class Person < ActiveRecord::Base
validates :name, presence: { strict: true }
end

Person.new.valid? #=> ActiveModel::StrictValidationFailed: Name can't be blank
Person.new.valid? # => ActiveModel::StrictValidationFailed: Name can't be blank
```

There is also an ability to pass custom exception to `:strict` option
Expand All @@ -724,7 +724,7 @@ class Person < ActiveRecord::Base
validates :token, presence: true, uniqueness: true, strict: TokenGenerationException
end

Person.new.valid? #=> TokenGenerationException: Token can't be blank
Person.new.valid? # => TokenGenerationException: Token can't be blank
```

Conditional Validation
Expand Down Expand Up @@ -917,7 +917,7 @@ validations fail.

Because every application handles this kind of thing differently, Rails does
not include any view helpers to help you generate these messages directly.
However, due to the rich number of methods Rails gives you to interact with
However, due to the rich number of methods Rails gives you to interact with
validations in general, it's fairly easy to build your own. In addition, when
generating a scaffold, Rails will put some ERB into the `_form.html.erb` that
it generates that displays the full list of errors on that model.
Expand Down

0 comments on commit 129eac0

Please sign in to comment.