Rails in a nutshell Глава 3. Active Record

Cody Fauser, James MacAulay, Edward Ocampo-Gooding, John Guenin, “Rails in a nutshell Chapter 3. Active Record”, public translation into Russian from English More about this translation.

See also 28 similar translations

Translate into another language.

Participants

skr1p7596 points
blandger189 points
GremL1N90 points
And others...
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next next untranslated
1 2 3 4 5 6 7 8 9 10 11 12

Rails in a nutshell Chapter 3. Active Record

Rails in a nutshell Глава 3. Active Record

History of edits (Latest: Elrick 2 years, 1 month ago) §

Chapter 3. Active Record

Глава 3. Active Record

History of edits (Latest: Elrick 2 years, 1 month ago) §

Connecting to a Database

Подключение к базе данных

History of edits (Latest: Elrick 2 years, 1 month ago) §

Before Active Record can work any of its ORM magic, it needs to know what kind of database it will be working with, and how it's going to connect to that database. In a Rails application, this involves a small configuration file located at config/database.yml. Rails loads the options defined in this file, stores them in a hash accessible as ActiveRecord::Base.configurations, and uses them to establish its database connections. By default, a freshly generated app starts off with a simple database setup that lets you get up and running without any manual configuration. Here's how the untouched database.yml looks:

Перед тем как Active Record сможет выполнять какую либо свою ORM магию, оно должно знать с каким типом баз данных оно будет работать и как ему подключаться к этой базе. В Rails приложении это решается небольшим конфигурационным файлом находящемся в config/database.yml. Rails загружает настройки объявленные в этом файле, располагает их в хэше доступном через ActiveRecord::Base.configurations, и использует их для установления соединения с базой данных. По умолчанию, только что сгенерированное приложение имеет базовые настройки базы данных, которые позволяют запустить приложение без какого либо предварительного конфигурирования. Файл database.yml по умолчанию выглядит так:

History of edits (Latest: GremL1N 1 year, 9 months ago) §

# SQLite version 3.x

# SQLite version 3.x

History of edits (Latest: skr1p7 1 year, 8 months ago) §

# gem install sqlite3-ruby (not necessary on OS X Leopard)

# gem install sqlite3-ruby (не нужно на OS X Leopard)

History of edits (Latest: skr1p7 1 year, 8 months ago) §

development:

development:

History of edits (Latest: skr1p7 1 year, 8 months ago) §

adapter: sqlite3

adapter: sqlite3

History of edits (Latest: skr1p7 1 year, 8 months ago) §

database: db/development.sqlite3

database: db/development.sqlite3

History of edits (Latest: skr1p7 1 year, 8 months ago) §

pool: 5

pool: 5

History of edits (Latest: skr1p7 1 year, 8 months ago) §

timeout: 5000

timeout: 5000

History of edits (Latest: skr1p7 1 year, 8 months ago) §

# Warning: The database defined as "test" will be erased and

# Предупреждение: База данных определенная как "test" будет стерта и

History of edits (Latest: skr1p7 1 year, 8 months ago) §

# re-generated from your development database when you run "rake".

# будет пересоздана из базы development когда вы запустите "rake"

History of edits (Latest: blandger 1 year, 2 months ago) §

# Do not set this db to the same as development or production.

# Не указывайте базу одинаковым именем для development или production разработки.

History of edits (Latest: blandger 1 year, 2 months ago) §

test:

test:

History of edits (Latest: skr1p7 1 year, 8 months ago) §

adapter: sqlite3

adapter: sqlite3

History of edits (Latest: skr1p7 1 year, 8 months ago) §

database: db/test.sqlite3

database: db/test.sqlite3

History of edits (Latest: skr1p7 1 year, 8 months ago) §

pool: 5

pool: 5

History of edits (Latest: skr1p7 1 year, 8 months ago) §

timeout: 5000

timeout: 5000

History of edits (Latest: skr1p7 1 year, 8 months ago) §

production:

production:

History of edits (Latest: skr1p7 1 year, 8 months ago) §

adapter: sqlite3

adapter: sqlite3

History of edits (Latest: skr1p7 1 year, 8 months ago) §

database: db/production.sqlite3

database: db/production.sqlite3

History of edits (Latest: skr1p7 1 year, 8 months ago) §

pool: 5

pool: 5

History of edits (Latest: skr1p7 1 year, 8 months ago) §

timeout: 5000

timeout: 5000

History of edits (Latest: skr1p7 1 year, 8 months ago) §

The adapter properties here are set so that each application environment gets its own SQLite3 database to work with. You will need to have the sqlite3-ruby gem installed before things can work properly. SQLite3 stores databases as single files with locations indicated by the database property of each environment's configuration, and each database is created automatically if it doesn't already exist. The pool property determines the maximum number of database connections in Active Record's connection pool. The timeout property is specific to the SQLite3 adapter and is discussed in ???.

В данном случае свойства адаптера установлены таким образом, что каждая среда разработки получит свою собственную базу данных для работы. Вам будет нужно иметь установленную библиотеку sqlite3-ruby до того, как све зарботает должным образом. SQLite3 сохраняет базу данных как единственный файл в месте указанным в свойстве для каждой конфигурации среды разработки и каждая база создается автоматически, если она еще не существует. Свойство 'pool' определяет максимальное количество соединений к базе в пуле соединений Active Record. Свойство 'timeout' является специальным в описании адаптера SQLite3 и обсуждается в .....???

History of edits (Latest: blandger 1 year, 2 months ago) §

If you want a new Rails application to be generated with defaults for some other database adapter, you can use the --database option:

Если вы хотите, чтобы новое Rails приложение было сгенерировано с другим адаптером базы данных, вы можете использовать параметр --database:

History of edits (Latest: skr1p7 1 year, 8 months ago) §

$ rails myapp --database=mysql

$ rails myapp --database=mysql

History of edits (Latest: skr1p7 1 year, 8 months ago) §

This will produce a different database.yml because the MySQL adapter works differently and requires a different set of information to manage its connections. The options for each adapter's configuration are detailed in ???.

Это создаст другой database.yml, потому что адаптер MySQL работает иначе и требует другой набор данных для управления подключениями. Параметры для настройки каждого адаптера, подробно изложены в ???.

History of edits (Latest: skr1p7 1 year, 8 months ago) §
Pages: ← previous Ctrl next next untranslated
1 2 3 4 5 6 7 8 9 10 11 12

© CC. License: CC