Forum: Ruby on Rails Connect to db table without needing blank models?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
luke (Guest)
on 2007-05-31 03:15
(Received via mailing list)

I'm wanting to get data from a table called ea_service_provider, and
have managed to do so by creating a blank file called
ea_service_provider.rb and with the following contents:

class EaServiceProvider < ActiveRecord::Base
  # model to interact with ea_service_provider table

This is so in another controller I can get the list of service
providers by:

@ea_service_providers = EaServiceProvider.find(:all);

I'm kind of unhappy having this file around just to interact with the
table. Can I use Rails to connect to an arbitrary table without
needing to create blank models?
Tyler MacDonald (Guest)
on 2007-05-31 03:28
(Received via mailing list)
If you find you have a lot of them, this might be worthwhile:


luke <removed_email_address@domain.invalid> wrote:
> >
MichaelLatta (Guest)
on 2007-05-31 05:35
(Received via mailing list)
If you want to use ActiveRecord to access your table then you need a
model.  You can always create the model class on the fly and throw it
away, but you need it.

If you just want to do an SQL query and do not need ruby objects back,
just do a query using the connection from any model class in the same


This topic is locked and can not be replied to.