Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6748631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:35:18+00:00 2026-05-26T12:35:18+00:00

I have a new rails app which needs to access data from a legacy

  • 0

I have a new rails app which needs to access data from a legacy table called “Doo_dad”, with an autoincrementing primary key called “id”, and a string field called “name”.

So I created a new model file called app/models/doodad.rb which looks like this:

class Doodad < ActiveRecord::Base
   set_table_name "Doo_dad"
end

When I loaded Rails console, I could reach my Rails-generated models, but I could not see the class

> rails console
irb> Doodad.class
NameError: uninitialized constant Doodad
(from (irb):1: in `evaluate`

Class Doodad in app/models/doodad.rb was not getting loaded. This code is good, because when I did the following:

> rails console
irb> class Doodad < ActiveRecord::Base
irb> set_table_name "Doo_dad"
irb> end
irb> Doodad.class
 => OK
irb> d=Doodad.new
irb> d.name="Uno"
irb> d.save
 => OK no errors

i.e. When I monkey-patched in the contents of app/models/doodad.rb, everything was fine, and the Doodad called “Uno” was saved into the database.

How can I get Rails to load up my model classes which hook up to legacy tables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:35:19+00:00Added an answer on May 26, 2026 at 12:35 pm

    D’oh! I had the class in app/models/doodads.rb. Once I renamed it to app/models/doodad.rb, everything was fine.

    I guess that the convention of one model class per file with the Rails model file naming convention (filename=classname.underscore+”.rb”) is an absolute “must” to get this working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A Ruby on Rails app will have access to a number of images and
I have a sequence of migrations in a rails app which includes the following
I'm pretty new to Rails and have an issue which I can't quite get
Starting a new rails project and we have a well-thought-out color palette, and want
I'm new to rails and have volunteered to help out the local High School
I am new to Rails routing and I currently have a problem and hope
I am fairly new to Rails and I have never developed a large application.
Hey, i have some experience with MVC. but I'm new to rails. I'm using
First of all, let me say I am very new to rails, have been
I am new to Ruby on Rails, I have completed the Blog Tutorial .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.