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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:57:39+00:00 2026-06-10T11:57:39+00:00

I started using rails today and got into a problem. I created three classes:

  • 0

I started using rails today and got into a problem.

I created three classes: Item, Requisito and Video. The last two has a scaffold item:references

Then I pointed the Item class to the other two items.

class Item < ActiveRecord::Base
  attr_accessible :materia
  has_many :requisitos
  has_many :videos
end

Now, I want to print everything in.

item.name

item.requisito.type

item.video.link

So I made this code.

<h1>Listing items</h1>

<table>
  <tr>
    <th>Materia</th>
    <th>Requisitos</th>
    <th>Videos</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @items.each do |item| %>
  <tr>
    <td><%= item.name %></td>
    <td>
        <% @items.requisitos.each do |requisito|%>
    <%= requisito.type %>
    <br>
    <% end %>
    </td>
<td>
    <% @items.videos.each do |video|%>
    <%= video.link %>
    <br>
    <% end %>
    </td>
   <td><%= link_to 'Show', item %></td>
   <td><%= link_to 'Edit', edit_item_path(item) %></td>
   <td><%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New Item', new_item_path %>

As you can see, I just gave a shot on how the code should be… and as I expected, it was wrong. Can someone please point out the right way to make it?

  • 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-10T11:57:40+00:00Added an answer on June 10, 2026 at 11:57 am

    Your nested each blocks should be iterating over item.requisitos not @items.requisitos (same for videos). So like this:

    <% item.requisitos.each do |requisito|%>
      <%= requisito.type %>
      <br>
    <% end %>
    

    and

    <% item.videos.each do |video|%>
      <%= video.link %>
      <br>
    <% end %>
    

    Hope that helps.

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

Sidebar

Related Questions

I have started using jQuery and rails. I have made a simple form that
I just get started using BDD in Rails application, but I'm not sure what
I've started using S3 to host images connected to Rails models. Images are not
I have recently started using RSpec for Integration testing in my Rails application, to
I just started using CakePHP for a small project. I have rails experience, and
I started using NetBeans today, and it was all going swimmingly, until I came
Started using thinking sphinx today and I'd like to know what's going wrong here:
I just started using Rails a few days ago, and I'm having trouble with
I just started using bundler with rails 2.3.8. After running bundler install there is
Rails 2.3.6 started using the fast new json library, yajl-ruby , if available .

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.