S
S
Said Dias2016-12-11 18:42:39
Ruby on Rails
Said Dias, 2016-12-11 18:42:39

Models in Rails, how to display information?

I want to page localhost:3000/teacher/index, fetch all names from the database
My controller is:
class TeachherController < ApplicationController
def index
@authors = Teacher.all
end
end
And the view is index
<%= @teachers.params %>
Teacher(id : integer, name: string, age: integer, created_at: datetime, updated_at: datetime)
And there are 3 Teachers
(not working)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Demidenko, 2016-12-11
@katatsu12

<% @teachers.each do |teacher| %>
  <%= teacher.name %>
<% end %>

E
Eugene Burmakin, 2016-12-12
@Freika

Dude, this is not the first time you've posted a simple question here. Learn to first formulate a query, then enter it into Google, and then follow the links and read, preferably google in English. There will be more results.
And read rusrails.ru from cover to cover.

A
Artem Gladyshev, 2016-12-12
@fairoj

<%= @teachers.map(&:name).join(', ') %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question