How to populate an HTML table from a design-generated database table
P粉521697419
P粉521697419 2024-04-05 09:13:39
0
1
2581

Very new to Ruby on Rails and devise. I'm currently trying to fill out a table on an HTML page that should list all the records from the Student table in my database (MYSQL).

<tbody>
<% for student in @students %>
 <tr>
  <td> <%= student.email %> </td>
 </tr>
<% end %>
</tbody>

I also tried @students.each |students|. Both variants give the error NoMethodError, undefined method 'each' for nil:NilClass According to the results of my online search, I am referencing the students table but not declaring it somewhere

def <name>
  @students = Students.all
end

As far as I know, it needs to go somewhere, but I don't know where.

Any suggestions on what to do would be great.

Rails 7.0.3 Design 4.8

P粉521697419
P粉521697419

reply all(1)
P粉704066087

You change Students to Student and use each to loop

Create: users_controller.rb

def index
 @students = Student.all
end

Create folder: views/users/index.html.erb

@students.each do |student|
// code
end
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template