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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:25:44+00:00 2026-06-17T22:25:44+00:00

I have 3 models: User, Order and UserOrder user_order.rb belongs_to :user, :class_name => User

  • 0

I have 3 models: User, Order and UserOrder

user_order.rb

belongs_to :user, :class_name => "User"
belongs_to :order, :class_name => "Order"

user.rb

has_many :user_orders, foreign_key: :user_id,
                      dependent: :destroy
has_many :ordering, through: :user_orders,
                  source: :order

order.rb

has_many :reverse_user_orders, foreign_key: :order_id, 
                              dependent: :destroy,
                              class_name: "UserOrder"

has_many :orderers, through: :reverse_user_orders, source: :user

I have controller action in orders_controller.rb, which creates the relationship between user and order and it works fine (it creates the record in the database)

 def create
 ...
   if @order.save
    current_user.order!(@order)
 ....

I want to render user.name in the orders’ index.html.erb file

<%= order.orderers.name %>

but in HTML it only renders caption “User”. If I use <%= order.orderers %> it returns the full hash, including user.name.

[#<User id: 19, name: "Peter Jackson", email: "foobar@vk.com", remember_token:   "pj6eI2mc2_6G0UbumoEqMA", password_reset_token: nil, password_reset_sent_at: nil, created_at: "2013-01-27 14:10:15", updated_at: "2013-01-27 14:10:28", provider: nil, uid: nil, passport: nil, region: "Zimbabve"]

Any way to render user.name in orders’ index.html.erb?
Thanks

  • 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-17T22:25:45+00:00Added an answer on June 17, 2026 at 10:25 pm
    <%= order.orderers.first.name %> #for the first orderer.
    
    <%= order.orderers.last.name %> #for the last orderer.
    

    of for each orderer:

    <% for o in order.orderers %>
      <%= o.name %>
     <% end %>
    

    Regards!

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

Sidebar

Related Questions

I have two models: User and Car with the following associations: User has_many Car
I have 2 models User and Address . class User < ActiveRecord::Base has_many :addresses
I have the following three models: class User < ActiveRecord::Base has_many :associations has_many :pharmacies,
I have two models: User and Store class Store < ActiveRecord::Base belongs_to :user class
I have some models as follows: Product: id name price Order: id user created
I have 4 models, Message, Group, User, Membership class Group < ActiveRecord::Base has_many :memberships
i have 3 models like : location, user, discovered_location(location_id,user_id) I think i need an
I have two models User and Category that have a HABTM association. I would
I have 2 models: User and Book and a join model ownership which connect
I have three models: User Image Group . User belongs to an image; Group

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.