I am trying to connect to an external database from my Rails
application. In my datanase.yml file, I have the following:
external_db:
adapter: mysql2
database: external_src
username: external_src
password: mypassword
host: myblog.com
The database is going to called to retrieve data for display in one of
the pages. I do have a pages controller, but I do not have a pages
model, so I created a pages mode, pages.rb and added the following to
it:
class Blog < ActiveRecord::Base
establish_connection(:external_db)
set_table_name :posts
end
Now, in my pages controller, how do I retrieve data? Let’s say I have a
table in that database called pots and I would like to retrieve the post
with the id 2? I tried: Blog.find(2), but I am getting the following
error message: uninitialized constant PagesController::Blog
Any ideas?