Skip to content

Instantly share code, notes, and snippets.

@fnichol fnichol/database.yml
Created Mar 24, 2011

Embed
What would you like to do?
An example using ActiveRecord to connect to a WordPress database
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: rails_proj_development
pool: 5
username: rp_dev
password: wootwoot
host: localhost
wp_development:
adapter: mysql2
encoding: utf8
reconnect: false
database: wpblog_dev
pool: 5
username: wp_user
password: hackable
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: rails_proj_test
pool: 5
username: rp_test
password: wootwoot
host: localhost
wp_test:
adapter: mysql2
encoding: utf8
reconnect: false
database: wpblog_test
pool: 5
username: wp_user
password: hackable
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: rails_proj_production
pool: 5
username: rp_prod
password: wootwoot
host: localhost
wp_production:
adapter: mysql2
encoding: utf8
reconnect: false
database: wpblog_prod
pool: 5
username: wp_user
password: hackable
host: localhost
##
# An example using ActiveRecord to connect to a WordPress database
#
module WordPress
class Post < ActiveRecord::Base
# tell active record to use another database connection
establish_connection "wp_#{Rails.env}"
# set the table name
set_table_name "wp_posts"
# normalize/sanitize some attributes to make things more railsy
alias_attribute "author", "post_author"
alias_attribute "posted_on", "post_date"
alias_attribute "posted_on_gmt", "post_date_gmt"
alias_attribute "content", "post_content"
alias_attribute "title", "post_title"
alias_attribute "excerpt", "post_excerpt"
alias_attribute "status", "post_status"
# add any virtual attributes to abstract gory details
def published?
self.status == "publish"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.