Prev | Current Page 29 | Next

David Berube

"Practical Reporting with Ruby and Rails"

establish_connection call.
Save this script as player_salary_ratio.rb. You can run this script using the following
command:
ruby player_salary_ratio.rb
Matthew 'm_giff' Gifford: $8090.91 per win
Matthew 'Iron Helix' Bouley: $18750.00 per win
Luke 'Cable Boy' Bouley: $10714.36 per win
Average Cost Per Win: $10863.66
Let??™s take a closer look at the techniques used to manipulate the database in this
example.
CHAPTER 1 n DATA ACCESS FUNDAMENTALS 8
Dissecting the Code
In Listing 1-2, first the ActiveRecord::Base.establish_connection method is used to establish
a connection to the database, as follows:
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root', # This is the default username and password
:password => '', # for MySQL, but note that if you have a
# different username and password,
# you should change it.
:database => 'players')
The adapter parameter is of particular interest. As you can infer from this line, you
can use other adapters to connect to other database types.


Pages:
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
bukmacher Ustawy Nr8 Betsson Poker linki sponsorowane księgarnia internetowa