【发布时间】:2014-10-20 00:06:58
【问题描述】:
我有一个 Student 模型,其中包含 name:string 和 classroom:string 列。
我希望有一个页面列出每个班级的学生。
即
localhost:3000/students/1E1
本地主机:3000/学生/1E2
本地主机:3000/students/1E3
等
我似乎无法解决问题。这是我尝试自己开发的第一个 Rails 应用程序。但我真的被困住了!希望有人可以帮助我。
这段代码在我的students_controller.rb中
class StudentsController < ApplicationController
def index
@students = Student.all
end
def show
@student = Student.find(params[:id])
end
def sort_by_class
@student = Student.find(params[:id])
@class = @student.classroom
end
end
此代码在我的 show.html.erb 中
<h1>Students#show</h1>
<p>Find me in app/views/students/show.html.erb</p>
<%= @student.name %>
<%= @student.classroom%>
【问题讨论】:
标签: ruby-on-rails