- ヘッダーメニューを作成して、ページ遷移をできるようにする
- 表示を正しくする。このように「 #Student:0x000055703d5c2c10」表示されている箇所を名前に変更する
- 生徒情報のGenderが「0」と「1」で表示されている所を、「male」「female」と表示されるように変更する
- 学科の詳細画面に、「所属している生徒」を表示します
- サークルの詳細画面に、「所属している生徒」を表示します
- サークルの一覧画面に、「所属している生徒の数」を表示します
- 生徒の詳細画面に、「所属しているサークル情報」と「テスト結果」を表示します
ヘッダーメニューを作成して、ページ遷移をできるようにする
application.html.erbを編集する
vi app/views/layouts/application.html.erb
app/views/layouts/application.html.erb
<head>
<title>CebuCollege</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<style type="text/css">
ul {
list-style: none;
}
li {
display: inline-block;
}
</style>
</head>
<body>
<ul>
<li>
<a href="/students" >生徒の一覧</a>
</li>
<li>
<a href="/subjects" >学科の一覧</a>
</li>
<li>
<a href="/exam_results" >試験結果の一覧</a>
</li>
<li>
<a href="/clubs" >サークル一覧</a>
</li>
</ul>
<%= yield %>
</body>
表示を正しくする。このように「 #Student:0x000055703d5c2c10」表示されている箇所を名前に変更する
変更対象のURL
http://192.168.33.10:3000/students
変更前
app/views/students/index.html.erb
<% @students.each do |student| %>
<tr>
<td><%= student.name %></td>
<td><%= student.subject %></td>
変更後(.nameを追加)
app/views/students/index.html.erb
<% @students.each do |student| %>
<tr>
<td><%= student.name %></td>
<td><%= student.subject.name %></td>
変更対象のURL
http://192.168.33.10:3000/exam_results
変更前
app/views/exam_results/index.html.erb
<% @exam_results.each do |exam_result| %>
<tr>
<td><%= exam_result.student %></td>
変更後(.nameを追加)
app/views/exam_results/index.html.erb
<% @exam_results.each do |exam_result| %>
<tr>
<td><%= exam_result.student.name %></td>
生徒情報のGenderが「0」と「1」で表示されている所を、「male」「female」と表示されるように変更する
app/models/student.rb
class Student < ApplicationRecord
belongs_to :subject
enum gender: { male: 0, female: 1 }
end