mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
dasherize titles in a more predictable way, and update fragment identifiers accordingly
This commit is contained in:
@@ -29,7 +29,7 @@ module RailsGuides
|
||||
return level_hash
|
||||
elsif level == current_level
|
||||
index = counters.join(".")
|
||||
bookmark = '#' + title.gsub(/[^a-z0-9\-_]+/i, '').underscore.dasherize
|
||||
bookmark = '#' + title.strip.downcase.gsub(/\s+|_/, '-').delete('^a-z0-9-')
|
||||
|
||||
raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{bookmark}). #{index}#{title}")
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ end
|
||||
>> Person.create.errors.invalid?(:name) # => true
|
||||
</ruby>
|
||||
|
||||
We'll cover validation errors in greater depth in the "Working with Validation Errors":#workingwith-validation-errors section. For now, let's turn to the built-in validation helpers that Rails provides by default.
|
||||
We'll cover validation errors in greater depth in the "Working with Validation Errors":#working-with-validation-errors section. For now, let's turn to the built-in validation helpers that Rails provides by default.
|
||||
|
||||
h3. Validation Helpers
|
||||
|
||||
|
||||
@@ -952,7 +952,7 @@ The +:source_type+ option specifies the source association type for a +has_one :
|
||||
|
||||
h6. :through
|
||||
|
||||
The +:through+ option specifies a join model through which to perform the query. +has_one :through+ associations were discussed in detail <a href="#thehas-onethrough-association">earlier in this guide</a>.
|
||||
The +:through+ option specifies a join model through which to perform the query. +has_one :through+ associations were discussed in detail <a href="#the-has-one-through-association">earlier in this guide</a>.
|
||||
|
||||
h6. +:validate+
|
||||
|
||||
@@ -1323,7 +1323,7 @@ The +:source_type+ option specifies the source association type for a +has_many
|
||||
|
||||
h6. +:through+
|
||||
|
||||
The +:through+ option specifies a join model through which to perform the query. +has_many :through+ associations provide a way to implement many-to-many relationships, as discussed <a href="#thehas-manythrough-association">earlier in this guide</a>.
|
||||
The +:through+ option specifies a join model through which to perform the query. +has_many :through+ associations provide a way to implement many-to-many relationships, as discussed <a href="#the-has-many-through-association">earlier in this guide</a>.
|
||||
|
||||
h6. +:uniq+
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ end
|
||||
This migration adds a +receive_newsletter+ column to the +users+ table. We want it to default to +false+ for new users, but existing users are considered
|
||||
to have already opted in, so we use the User model to set the flag to +true+ for existing users.
|
||||
|
||||
NOTE: Some "caveats":#using-modelsin-your-migrations apply to using models in your migrations.
|
||||
NOTE: Some "caveats":#using-models-in-your-migrations apply to using models in your migrations.
|
||||
|
||||
h4. Migrations are Classes
|
||||
|
||||
@@ -76,7 +76,7 @@ Active Record provides methods that perform common data definition tasks in a da
|
||||
* +add_index+
|
||||
* +remove_index+
|
||||
|
||||
If you need to perform tasks specific to your database (for example create a "foreign key":#active-recordand-referential-integrity constraint) then the +execute+ function allows you to execute arbitrary SQL. A migration is just a regular Ruby class so you're not limited to these functions. For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models).
|
||||
If you need to perform tasks specific to your database (for example create a "foreign key":#active-record-and-referential-integrity constraint) then the +execute+ function allows you to execute arbitrary SQL. A migration is just a regular Ruby class so you're not limited to these functions. For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models).
|
||||
|
||||
On databases that support transactions with statements that change the schema (such as PostgreSQL), migrations are wrapped in a transaction. If the database does not support this (for example MySQL and SQLite) then when a migration fails the parts of it that succeeded will not be rolled back. You will have to unpick the changes that were made by hand.
|
||||
|
||||
@@ -327,7 +327,7 @@ end
|
||||
</ruby>
|
||||
will add an +attachment_id+ column and a string +attachment_type+ column with a default value of 'Photo'.
|
||||
|
||||
NOTE: The +references+ helper does not actually create foreign key constraints for you. You will need to use +execute+ for that or a plugin that adds "foreign key support":#active-recordand-referential-integrity.
|
||||
NOTE: The +references+ helper does not actually create foreign key constraints for you. You will need to use +execute+ for that or a plugin that adds "foreign key support":#active-record-and-referential-integrity.
|
||||
|
||||
If the helpers provided by Active Record aren't enough you can use the +execute+ function to execute arbitrary SQL.
|
||||
|
||||
@@ -410,7 +410,7 @@ Neither of these Rake tasks do anything you could not do with +db:migrate+, they
|
||||
|
||||
Lastly, the +db:reset+ task will drop the database, recreate it and load the current schema into it.
|
||||
|
||||
NOTE: This is not the same as running all the migrations - see the section on "schema.rb":#schema-dumpingand-you.
|
||||
NOTE: This is not the same as running all the migrations - see the section on "schema.rb":#schema-dumping-and-you.
|
||||
|
||||
h4. Being Specific
|
||||
|
||||
|
||||
Reference in New Issue
Block a user