establish_connection(
:adapter => "mysql",
:host => 'insert_your_mysql_hostname_here',
:username => 'insert_your_mysql_username_here',
:password => 'insert_your_mysql_password_here',
:database => 'paypal')
This creates a connection for use by Active Record, so all of your later code will use
this connection. If you wanted to connect to a different database, such as PostgreSQL or
SQLite, you could change the adapter parameter to use a different adapter. (Note that these
parameters are similar to those that you??™ll find in a Rails application??™s database.yml file.)
Next, the following line creates a very simple model, called PayPalTransaction:
class PaypalTransaction < ActiveRecord::Base
end
Because the class inherits from ActiveRecord::Base, it automatically gets a number of
methods based on the characteristics of the paypal_transactions table. See Chapter 1 for
more information about Active Record models.
You also extend the String class:
class String
def columnize
self.strip.downcase.gsub(/[^a-z0-9_]/, '_')
end
end
CHAPTER 7 n TRACKING EXPENDITURES WITH PAYPAL 141
This adds a method, columnize, to all strings.
Pages:
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208