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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:30:34+00:00 2026-06-05T21:30:34+00:00

This is probably a very simple question, I apologise – I’m new to rails.

  • 0

This is probably a very simple question, I apologise – I’m new to rails.

I’ve got 2 controllers – customers and orders. I’ve got it so that when a customer places an order, their id is passed in a hidden field, so that the customer_id field in the orders table has their id. So all orders have the id of the customer who placed it. What I’m trying to do is have the show view for the customers display all their orders – so all the orders with their id.

I’ve got the customer has_many orders and orders belong_to customers etc. How do I reference the customers/orders to extract the right info? And do I need to put extra info in the show action on the controller? I’ve tried everything I can think of! So far, I’ve been able to get a hash of all the info to appear in the show view, but I can’t get individual bits of info to appear – e.g. order.price.

I basically want a table of the order details in the customers show view – order price, date placed etc. Any help would be much appreciated, thanks!

Edit: I now have this – but can’t get the line_items bit to work. The relationships work like this: customer has many orders, orders have many line items, line items belong to products. I suspect the reason it’s not working is because of the belongs_to.

<% @customer.orders.each do |order| %>
    <% order.line_items.each do |line_item| %>
        <tr>
            <td><%= line_item.created_at %></td>
                <% line_item.products.each do |product| %>
                    <td> <%= product.name %></td>
                <% end %>
            <td><%= order.email %></td>
        </tr>
    <% end %>
<% end %>
  • 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-05T21:30:36+00:00Added an answer on June 5, 2026 at 9:30 pm

    You shouldn’t need to add anything to the controller show action.

    In your customer show view you presumably have access to a @customer object. Because of your has_many, that will have a collection @customer.orders. So, in the view, you can do something like

    <table>
    <thead>
       <td>Item</td>
       <td>Quantity</td>
       <td>Price</td>
       <td>Date Placed<td>
    </thead>
    
    <% @customer.orders.each do |order| %>
    <tr>
       <td><%= order.item.name %></td>
       <td><%= order.quantity %></td>
       <td><%= order.price %></td></tr>
       <td><%= order.date_placed %></td>
    </tr>
    <% end %>
    
    </table>
    

    Obviously I’m making up the possible order fields you’d want to display, but this should give you the idea.

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

Sidebar

Related Questions

This is probably a very simple question. I am new to Rails and have
This is probably a very simple question to answer. i am new to Rails
I'm new to Xcode. This is probably a very simple question to you, but
This is probably a very simple question. Say I had a class that computed
This is probably a very simple question that I am working through in an
I'm new to nuget and this is probably a very simple question but I
I know this is probably a very simple question but how would I do
Okay, this is (probably) a very simple question, but I am afraid I know
I feel like the answer to this question is probably very simple, but I'm
This is a very simple, probably too simple question but I'm afraid my limited

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.