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

  • Home
  • SEARCH
  • 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 9051439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:54:20+00:00 2026-06-16T12:54:20+00:00

I have an invoice model that has many_invoice items class Invoice < ActiveRecord::Base belongs_to

  • 0

I have an invoice model that has many_invoice items

class Invoice < ActiveRecord::Base
  belongs_to :customer, :inverse_of => :invoices
  attr_accessible :approved_by, :due_date, :invoice_date, :reading_ids, :terms, :customer_id, :customer, :status

  validates :invoice_date, presence: true
  validates :due_date, presence: true
  validates :customer, presence: true
  has_many :invoice_items
  accepts_nested_attributes_for :invoice_items
end

Invoice Items Model

class InvoiceItem < ActiveRecord::Base
  belongs_to :invoice
  attr_accessible :amount, :description, :rate, :tax_amount
end

I now have a show action in my Invoices_controller

def show
@invoice = Invoice.find(params[:id])
respond_to do |format|
    format.html
end
end

I want to be able to show the invoice_items like description, tax amount and rate in the show page for the invoices however, it is giving me quite a challenge. Do I have to create a partial in there that deals with the invoice items? Below is my show page

<p id="notice"><%= notice %></p>
<div class="row">
<div class="span12">
    <h3> Customer Invoices </h3>
<table class="table table-striped">
  <thead>
    <tr>
      <th>Invoice ID </th>
      <th>Customer Name </th>
      <th>Invoice Date </th>
      <th>Due Date </th>
      <th>Amount</th>     
   </tr>
</thead>
<tbody>
  <tr>
    <td><%= @invoice.customer.name %></td>
    <td><%= @invoice.invoice_date %></td>
    <td><%= @invoice.due_date %></td>   
  </tr>
</tbody>
</table>
</div>
</div>
  • 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-16T12:54:21+00:00Added an answer on June 16, 2026 at 12:54 pm

    using a partial is not a must, but you could do this in either way

    1 – with out a partial

    in your show.html.erb
    
    #your invoice code
    <% invoice_items = @invoice.invoice_items %>
    <% invoice_items.each to |invoice_item|%>
    <tr>
      <td><%= invoice_item.amount%></td>
    </tr>
    <% end %>
    

    2 ) with a partial

    in your show.html.erb
    
    #your invoice code
        <% invoice_items = @invoice.invoice_items %>
        <% invoice_items.each to |invoice_item|%>
        <tr>
          <td>
             <%= render :partial => 'invoice_item', :locals => {:item => invoice_item}%>
          </td>
        </tr>
        <% end %>
    
     in your _invoice_item.html.erb
    
     <%= item.name %>
    

    HTH

    • 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. I have a form
I have a Customer and Invoice Model. A customer has many invoices and an
I have these two models class Invoice < ActiveRecord::Base has_many :items accepts_nested_attributes_for :items ...
I have a model Invoice with attribute payment_status. payment_status has fixed values unpayed|partial_payed|payed that
Picture a normal invoice: On it, you have several items. Each item has a
I am testing an Invoice model (a Client has many invoices, an Invoice belongs
I have a working model in coredata with two entity: - Customer - Invoices
I'm editing my invoices file in /Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php And I'm running into a problem with
Let's say I have a User model, and an Invoice model with a belongs_to
I have an Invoice model which belongs to Customer (and of course Customer has_many

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.