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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:47:02+00:00 2026-06-16T11:47:02+00:00

I have a Customer and Invoice Model. A customer has many invoices and an

  • 0

I have a Customer and Invoice Model. A customer has many invoices and an invoice belongs_to a customer.

class Customer < ActiveRecord::Base
 attr_accessible :billing_address, :customer_currency, :email, :first_name, :last_name,    :mobile, :name, :payment_terms, :phase_type, :pays_vat
 validates_presence_of :first_name, :last_name, :mobile, :billing_address, :payment_terms,  :phase_type, :customer_currency

has_many :invoices

validates :email, 
        :presence => true,
        :uniqueness => true, 
        :email_format => true

validates :name, :mobile, :presence => true, :uniqueness => true
end

Invoice Model is

class Invoice < ActiveRecord::Base
belongs_to :customer
attr_accessible :approved_by, :due_date, :invoice_date, :terms, :customer_id, :customer

validates :invoice_date, presence: true
validates :due_date, presence: true
validates :customer, presence: true

I am trying to create an index page that lists all the invoices in the system and this will invoice showing a customer Name to whom the invoice belongs. How can i retrieve that and clearly depict it in my model and view?

  • 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-06-16T11:47:04+00:00Added an answer on June 16, 2026 at 11:47 am

    I think you’ve already created customer and invoice controllers and views (if not do it by generate scaffold). Then list invoices in views\invoices\index.html.erb:

    <table>
      <tr>
        <th>Invoice</th>
        <th>Customer/th>
      </tr>
    <% @invoices.each do |invoice| %>
      <tr>
        <td><%= invoice.num %></td>
        <td><%= invoice.customer.first_name %></td>
      </tr>
    <% end %>
    </table>
    

    Of course, you should declare @invoices in controllers/invoices_controller.rb

    def index
      @invoices = Invoice.includes(:customer).all
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an invoice model that has many_invoice items class Invoice < ActiveRecord::Base belongs_to
I have the following model associations Customer model class Customer has_many :readings has_many :invoices
I have a working model in coredata with two entity: - Customer - Invoices
I have an Invoice model which belongs to Customer (and of course Customer has_many
I have a table which has a list of invoices and their details: class
I have an customer invoice table in my MySQL database with a DECIMAL(10,2) field
Scenario: Say I am on an invoice details page. I have a customer name
I have a Customer class that contains a property, MyProperty, which is of a
PHP: If I have a customer class, and the customer can have a car
I have a item tracking system which has an Item model which has a

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.