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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:06:15+00:00 2026-05-12T09:06:15+00:00

Its maybe not the best solution in most cases, but i want a table

  • 0

Its maybe not the best solution in most cases, but i want a table with data form 3 tables.

class Media < ActiveRecord::Base
  belongs_to :user
  belongs_to :type
  has_many :ratings                                           
end

class User < ActiveRecord::Base
  has_many :medias
  has_many :ratings
end

class Rating < ActiveRecord::Base
  belongs_to :user
  belongs_to :media
end

Thats the view I want

<table>
  <tr>
    <th>Name</th>
    <th>Comment</th>
    <th>Creator</th>
    <th>Type</th>
    <% for user in @users %>
      <th><%=h user.login %></th>
    <% end %>
  </tr>

<% for media in @medias %>
  <tr>
    <td><%=h media.name %></td>
    <td><%=h media.comment %></td>
    <td><%=h media.user.login %></td>
    <td><%=h media.type.name %></td>
    <% for user in @users %>
      <td><%=h GET_RATING (media, user) %></td>
    <% end %>%>
  </tr>
<% end %>
</table>

Basicly i want one new row for each users ratings for each media

What I want is a Table that looks like that:

media.name  media.comment ...   rating(media, user).rating

I think it would be better to use a join in the Controller with the Media find methods but I dont know how exactly, enougher possible solution could be helper method that takes media and user as parameters.

What do you think is the best solution for this?

  • 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-12T09:06:15+00:00Added an answer on May 12, 2026 at 9:06 am

    This kind of association belongs in your model, a has many through relationship is perfect for this.

    class User < ActiveRecord::Base
      has_many :ratings
      has_many :media, :through => :ratings
    end
    
    class Media < ActiveRecord::Base
      has_many :ratings
      has_many :users, :through => ratings
    end
    
    class Rating < ActiveRecord::Base
      belongs_to :user
      belongs_to :media
    end
    

    Then you can access

    media.name media.comment 
    

    Then could also access

    user.ratings
    

    or:

    <% media.users.each do |user| %>
      ## Do stuff with user.ratings array
    <% end %>
    

    You can also:

    media.ratings.each do |rating|
      rating.your_attribute
      rating.user.your_attribute
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having issues getting this to work, maybe its not even possible? I have
Maybe it's not worth worrying about in this scenario, but lets say you have
Maybe its a very dumb question but I hope you can give me some
Maybe its because I've been coding around two semesters now, but the major stumbling
I want to be able to pass anything to a git command (maybe its
maybe it's not so proper to ask this question here... anyway, I'm trying to
Does anyone know off a way or maybe think its possible to connect Node.js
Very direct question, i need to know if its possible and maybe where to
Is it possible to have an enum change its value (from inside itself)? Maybe
Maybe it's just me, but I cannot understand the documentation regarding Junit test integration

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.