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 7612011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:48:23+00:00 2026-05-31T01:48:23+00:00

Hi there Im a beginner to rails and what Im doing seems a common

  • 0

Hi there Im a beginner to rails and what Im doing seems a common usecase to me yet, its funny it seems so hard to do in Rails and not many posts on the internet about the topic:

  1. I created a new rails app. Since I had a legacy database that I wanted to include in my new rails app, I replaced the “development.sqlite3” with the legacy database “Listings.sqlite3”

  2. Then I generated a model “business.rb” to match the table “Businesses” in my legacy db. Here is the code for it:

    class Business < ActiveRecord::Base
    
      establish_connection "Listings_development"
    
    end
    
  3. Then I modified the “config/database.yml” file to include the following:

    Listings_development:
      adapter: sqlite3
      database: db/Listings.sqlite3
      pool: 5
      timeout: 5000
    
    Listings_test:
      adapter: sqlite3
      database: db/Listings.sqlite3
      pool: 5
      timeout: 5000
    
    Listings_production:
      adapter: sqlite3
      database: db/Listings.sqlite3
      pool: 5
      timeout: 5000
    
  4. After that I generated the controller called “businesses_controller.rb” which has the following code:

    class BusinessesController < ApplicationController
      def show
    
      end
    
      def index
        @businesses = Business.all
        respond_to do |format|
          format.html #index.html.erb
        end
      end
    end
    
  5. Finally I changed the “config/routes.rb” file to the following:

    Directory::Application.routes.draw do
      resources :businesses
    
    
      get "business/index"
    
      match ':controller(/:action(/:id))(.:format)'
    
  6. Lastly I added a view file “index.html.erb:

    <h1>Listing businesses</h1>
    <table>
      <tr>
        <th>Name:</th>
        <th>Phone Number:</th>
        <th>Address:</th>
      </tr>
    
    <% @businesses.each do |business| %>
      <tr>
        <td><%= business.company_name %></td>
        <td><%= business.phone_number %></td>
        <td><%= business.address %></td>
    

I thought I was done, I had successfully managed to incorporate my legacy database and its data in my new rails app. But when I typed in “http://localhost:3000/businesses/” in my browser window. I get this error on the screen:

Showing /Users/AM/Documents/RailsWS/cmdLineWS/Directory/app/views/businesses/index.html.erb
where line #14 raised:

undefined method `company_name' for #<Business:0x00000104e1d0e8>
Extracted source (around line #14):

11: 
12: <% @businesses.each do |business| %>
13:   <tr>
14:     <td><%= business.company_name %></td>
15:     <td><%= business.phone_number %></td>
16:     <td><%= business.address %></td>
17:     <td><%= link_to 'Show', business %></td>
Rails.root: /Users/AM/Documents/RailsWS/cmdLineWS/Directory

Whats up with Rails?? Is it really that complex to include a legacy db? I thought the whole point of rails was rapid prototyping.

Here is a snapshot of my Listings.db file
enter image description here

  • 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-31T01:48:24+00:00Added an answer on May 31, 2026 at 1:48 am

    The problem could be caused by the fact the businesses’ columns contains spaces and uppercase chars (e.g. I see “Company Name” in the screenshot instead of the wanted “company_name”). I don’t know if rails support this kind of attribute names.

    BTW is not a good practice have spaces and other strange characters in column names (in my humble opinion)

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

Sidebar

Related Questions

I'm a beginner in Flex so there must be more elegant way of doing
OK, so I've read through various posts about teaching beginner's to program, and there
I am a beginner in Rails. In the following code,there is an id which
I am a beginner at rails development and moved from cakephp. In cakephp there's
Brief question, beginner's work on Ruby/Rails. Here's my view: <h1>News</h1> <%= @posts.each do |post|
I'm a beginner so if there is a terminology for what I'm doing I
I'm a beginner and there's something that's not making much sense to me. Please
i am beginner of creating web services in java.i saw there are many ways
Is there an easy beginner way to take the current time using <ctime> to
I am a C# beginner. I found there are 2 way to write codes

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.