Z
Z
zggb2014-12-10 18:30:12
Ruby on Rails
zggb, 2014-12-10 18:30:12

How to display data using has_many belongs_to binding methods?

There are models:
User has_many tests
Test belongs_to User
There is a /users/index page where user cards are displayed.
To display information from the tests table, I use

<% @users.each do |user| %>
  <%= user.tests.each do |f| %> 
    <%= f.title %>
  <% end %>
<% end %>

Everything is displayed perfectly, except for an extra trailer in the form of:
[#<Test id: 1, title: "number 1", describe: " blablabla", 
user_id: 1, created_at: "2014-12-10 13:22:15", 
updated_at: "2014-12-10 13:22:15">]

Can you please tell me how to remove it? and where to read the theory why it is generated?
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Platonov, 2014-12-10
@zggb

<% @users.each do |user| %>
  <% user.tests.each do |f| %> 
    <%= f.title %>
  <% end %>
<% end %>

<% something %> - executes ruby ​​code
<%= something %> - outputs output
Read this:
stackoverflow.com/questions/7996695/what-is-the-di...

S
Sergey Krasnodemsky, 2014-12-10
@Prognosticator

where is the excess output?
f.title what outputs?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question